-
Notifications
You must be signed in to change notification settings - Fork 297
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
Add CloseNow that doesn't block #384
Comments
I'd argue that We have a component called the connection manager, which at regular intervals prunes existing connections. It's not uncommon for us to close 100s of connections at a time. If (in the worst case) all of those are WebSocket connections and take 5s to close, that's a big problem, as the connection manager loop now spends 20 minutes on closing those connections. Of course, I could spawn a new Go routine for each
Is there really no way to just tell this library "send the Close frame and walk away"? It would be ok if that function was not called |
Fair enough. I'll add a |
I should mention, I've written similar connection managers and the way I've solved this problem is I don't have the connection manager close the connection. It merely cancels a context that triggers the goroutine reading from the WebSocket to exit and thus close it. Then I use a waitgroup to wait until all active websocket goroutines are finished. I've been meaning to make this code available in the library too #209 |
Done in dev. |
@nhooyr I managed to condense it down to a minimal test case that reliably reproduces the bug. There's no read and write calls at all, just the server closing the connection right after accepting it.
I'm not very familiar with the code base (nor with the WebSocket protocol itself), but here's where the
Close
call gets stuck: https://github.com/nhooyr/websocket/blob/14fb98eba64eeb5e9d06a88b98c47ae924ac82b4/close_notjs.go#L108Maybe I'm thinking in the wrong direction here, but this is surprising to me. Why do we need to read anything when closing? I would've expected us to just write a Close frame and then return.
Originally posted by @marten-seemann in #355 (comment)
The text was updated successfully, but these errors were encountered: