You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update FakeStream::{trailers,headers} to address thread safety warnings
Returning reference trips thread safety analysis in clang-18, because
returning a reference to a lock protected member is in general
incorrect.
I don't think that this is in practice causing any problems because
tests call one of the waitForX functions before calling trailers/headers
methods and thus by the time trailes/headers is being called synchronization
would have already happened (and in the same thread).
Still, we do want to migrate to a newer toolchain, so we should address
those warnings to make clang-18 and transitively Envoy CI happy.
I'm changing trailers to return a copy of a shared pointer instead of
returning a reference to a pointer. While it changes the return type,
it should not affect any callers.
For headers it's a bit more complicated, as it returns a reference. To
avoid changing the interface and updating multiple tests that use the
headers method we went with a somewhat different approach that relies on
a couple of assumptions:
1. headers() method is only called from a single thread, which may or
may not be different from the thread that calls decodedHeaders()
2. headers cannot be updated in place - only replaced completely.
With those two assumptions we can maintain two header maps, one for
internal use (headers_) and one for the clients (client_headers_).
The client_headers_ map is only accessed in the headers() method and
therefore does not require a lock. headers_ map can be accessed
from multiple threads, so it does require a lock, but it's purely
internal and we do not expose it outside of the class.
In the headers() method call we move the data from headers_ to
client_headers_ if the data changed and return a reference to the new
client_headers_.
Signed-off-by: Mikhail Krinkin <[email protected]>
Signed-off-by: Mikhail Krinkin <[email protected]>
0 commit comments