Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wave need for locking when calling FakeStrea::{body,headers,trailers}
Those return references to internal protected members, so ideally all the callers should acquire a lock before calling those. However, all the tests that use FakeStream or one of its derivatives cannot really acquire the right lock because it's a protected member of the class. We got away with this so far for a few reasons: 1. Clang thread safety annotations didn't detect this problematic pattern in the clang-14 that we are currently using (potentially because those methods actually acquired locks, even though those locks didn't actually protect much). 2. The locks are really only needed to synchronize all the waitForX methods, accesors methods like body(), headers() and trailers() are called in tests after the appropriate waitForX method was called. Disabling thread safety annotations for these methods does not actually make anything worse, because the existing implementation aren't thread safe anyways, however here are a few alternatives to disabling those that I considered and rejected at the moment: 1. Return copies of body, headers and trailers instead of references, create those copies under a lock - that would be the easiest way to let compiler know that the code is fine, but all three methods return abstract classes and currently there is no easy way to copy them (that's not to say, that copying is impossible in principle); 2. Expose the lock and require all the callers acquire it - this was my first idea of how to fix the issue, but FakeStream (and it's derivatives) is used quite a lot in tests, so this change will get quite invasive. Because it does not seem like we really need to lock those methods in practice and given that alternatives to disabling thread safety analysis on those are quite invasive, I figured I can just silence the compiler in this case. Signed-off-by: Mikhail Krinkin <mkrinkin@microsoft.com>
- Loading branch information