-
Notifications
You must be signed in to change notification settings - Fork 85
Fix ThreadSanitizer errors #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I'm not convinced. It shouldn't be possible for state.reset() and state.parse() to be executing at the same time. If this is happening, adding a mutex won't solve the issue..you'll get a reset of data in the middle parsing..that won't be right. If this is happening, I'd rather figure out why and fix it at the root. |
With 44f050e I don't get any tsan errors. But I find it weird that that simple change fixed warnings/errors that didn't seem related. |
I don't disagree with this, I don't mind spending some more time unraveling things to get to the root
😅 or maybe you already figured it out
this change actually seems similar to 5bca6b2 from this PR. In fact, it seems identical, since as far as I can tell
With 74df8f9 I'm able to produce the ThreadSanitizer output that prompted the additional commits on this PR. I'm not sure why, but my gut tells me that if we're using atomic operations anywhere for |
<edit: removed diff, pushed requisite changes> |
Signed-off-by: Wolfgang E. Sanyer <[email protected]>
Specifically, State.parse and State.reset are called from multiple threads, leading to data races since both mutate the state of...well State. Signed-off-by: Wolfgang E. Sanyer <[email protected]>
This is used in requestDone to ensure that multiple threads don't race to mutate the state. Signed-off-by: Wolfgang E. Sanyer <[email protected]>
This mutex prevents data races surfaced by ThreadSanitizer. Signed-off-by: Wolfgang E. Sanyer <[email protected]>
Signed-off-by: Wolfgang E. Sanyer <[email protected]>
bbe3169
to
74df8f9
Compare
hm weird, at first running tests off of 44f050e resulted in no more ThreadSanitizer output, but after rerunning it a few times it came back:
|
@ezzieyguywuf are you on Mac or Linux? I can't reproduce this. The stack that you provided tell me that it's trying to process multiple websocket messages at the same time. When the connection is upgraded, we switch to oneshot/dispatch in epoll/kqueue. Could definitely be an issue with how that's done. |
I'm on linux |
Based on https://nullprogram.com/blog/2022/10/03/ it seems that TSan does generate false positives when used with epoll and oneshot (which is what httpz is doing with websocket connections). I tried to look into it, and I've yet to observe multiple threads concurrently accessing Gonna keep looking into it. |
eyy nice find. I can see if there's a way to tell tsan to ignore one particular spot. |
I did not do any performance testing to establish the performance impact of
these various new mutexes. If someone can point me towards some documentation on
how to execute performance tests on this project I'm happy to do this analysis.
I also didn't spend too much time thinking about whether or not larger design
changes may be necessary (e.g. I don't know why multiple threads are calling
processWebsocketData or State.reset()/State.parse()) - instead I opted for the
more straightforward approach.
I'm happy to use this PR as a conversation started if necessary.