-
Notifications
You must be signed in to change notification settings - Fork 138
websocket: prevent deadlocks #407
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: main
Are you sure you want to change the base?
websocket: prevent deadlocks #407
Conversation
c5e0355 to
845628c
Compare
452d39f to
c3c0cc0
Compare
c3c0cc0 to
50ba8c0
Compare
|
I repeatedly amended and pushed my commit to re-run the tests. The 8th time it failed, it seems there is a deadlock in the code. |
21e0698 to
24ed421
Compare
0af0f08 to
366f1f3
Compare
366f1f3 to
50ba8c0
Compare
fa5ed52 to
e4b8869
Compare
034b115 to
f97ba73
Compare
f97ba73 to
2523e2a
Compare
|
Hi @benjaminjkraft, I'm at a bit of a loss here. The deadlock in the tests seems going be stemming from the forwardData will still holding a lock. However, deleting it exposes a situation where we can end up writing on a closed channel. That gives a panic which could be caught and ignored. But that seems like a very bad way to handle problems. There seems to be an inherent race condition between checking isClosing and actually using channel. It's seems tricky to actually make this atomic. Do you have any ideas? |
210caa3 to
a984656
Compare
b56cbd8 to
d6b326f
Compare
d6b326f to
f9a5e5d
Compare
2fa4559 to
01125ae
Compare
01125ae to
9f24ffc
Compare
bcce435 to
9f24ffc
Compare
benjaminjkraft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this gets kinda complicated. I would need to think some more to see if I think it's right (for example I sure don't recall the rules for atomics). It feels like it's just sweeping problems under the rug.
I was too lazy to think so I gave this to Claude, who refactored to have just one lock (in the client); this passes the tests at least and seems less likely to have a hidden deadlock, although I'm not sure if I fully understand what invariants we need to ensure. Does having two actually let us be meaningfully more granular? (Or, can we ensure we always take the two locks out in some order? And we should probably regardless ensure we never hold a lock during network operations or calls to user-controlled code.)
|
@benjaminjkraft Makes sense, I added some comment on the PR. Thanks for the help! ❤️ |
Follow-up to #402 (comment).