-
Notifications
You must be signed in to change notification settings - Fork 312
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
Write doesn't check if connection is closed before returning error #215
Comments
Is your echo server written with this library? The error indicates the library did not receive a close frame from the peer. |
Will note that I should add an error wrap in https://github.com/nhooyr/websocket/blob/ff876f6d14d96bf1de6094887d6bbf167991b046/close_notjs.go#L83 to make that clear. |
The echo server used is hosted by 3rd party. (It has some strange behavior on continuation frame, but not related to this issue.)
Yes, you're right. Actually this code does not correctly expose what I want to show. I'll rewrite the code and post later. |
The code I provided does not show the problem clearly. I'm going to close this issue and open another. |
All in progress reads and writes will do what you describe. But the close itself will return an IO error if it occurred as that means the close handshake wasn’t done. |
Nvm it looks like I missed this on writes when I recently refactored the library. Thanks for reporting will fix soon. |
If Conn.Close is called when there's on-going read/write, read/write may return I/O error instead of wrapping a CloseError, and there is no trivial way to examine whether this I/O error is caused by calling Conn.Close.
Of course I can record the code and reason before I call Conn.Close, but there is still a race between my call to Conn.Close and something like WebSocket protocol error. My recorded code and reason may not reflect what actually sent to remote peer in the close frame.
How to reproduce
Expected output
Actual output (sometimes, due to race)
The text was updated successfully, but these errors were encountered: