-
Notifications
You must be signed in to change notification settings - Fork 311
Perform WebSocket Close handshake in Conn.Close #104
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
Conversation
This won't work as is due to the limitation that you must be reading in another goroutine for the peer's close frame to be detected. You might have an error in the reading goroutine and then call Close() to write a close frame. E.g. the JSON was invalid. You can't have Close block on waiting for a close frame from the client as no goroutine is reading from the connection. Not sure the best way to solve this. |
If the application decides to initiate the handshake from the reading goroutine, then the application must start a goroutine to call Close. This seems complicated. |
Yea no I agree. It's not going to be merged as is. I think if Close is called, we take the read lock and write all read data messages to ioutil.Discard until we find the close frame for a max 10 seconds. This seems pretty reasonable. I'm not sure if the Readering goroutine should block on obtaining the read lock or if it should error out immediately as it cannot read from the connection now that the closing handshake has started. |
Discarding the message is no different from closing the connection immediately. Either way, the application cannot receive messages until the peer is done sending. |
It is different as once the close frame has been received, you know the peer received all of your messages. If you're sending a close frame, why would you still want to receive messages from the peer? The RFC says
|
@stephenyama What would you want the library to do instead? |
With your latest proposal, the application can determine if the peer received all messages. What's missing is a way to receive any responses to those messages. A closing handshake is not unique to WebSockets. One example is the HTTP/1.1 How about something like this?
|
There is no guarantee that the peer will respond to any of those messages. It's explicitly stated in the RFC that you shouldn't rely on it. The problem with your API proposal is that sending a close frame isn't really the same as closing the write side of the connection, it's saying I'm not going to be sending any more messages and I don't want to receive any more messages either and will close this connection. |
Don't think I'll be moving forward with this. See discussion in #103 |
Closes #103
@stephenyama Could you please review?