-
Notifications
You must be signed in to change notification settings - Fork 221
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
Review closing the connection #77
Comments
I think it's only one concern, the first one in your list, but since it's not explicitly coded as a state machine, it looks confusing.
Correct.
You will get inside this block in the following scenario: you're using the library on the server side. At one point you decide to close the connection and send a close frame to the user. The user replies to it. The execution will then get to this part of There was also some test written for that: |
The connection on the client side will be terminated after server closes the socket.
No, you'll only get to that part of code when the send queue is empty (that's also documented in a comment above that block of code). |
That's just a documentation error. Just note that it is possible to receive a Protocol error followed by AlreadyClosed without ever receiving ConnectionClosed. From here.
I'm sorry, that's my bad. In that case, there isn't an actual error here. So I'll close this issue. |
Yeah, I mean... of course if there is a protocol violation (a bug on one of the sides), then you can get this error instead of |
In a similar idea of #76 I would like to have a look at this part of
WebSocketContext::write_pending
:Note that right now the code still does a check on
WebSocketState::ClosedByPeer | WebSocketState::CloseAcknowledged
, but that's exactly whatcan_read
covers, namely that we received a close frame from the remote, so I cleaned that up a bit.This code mixes 2 concerns:
ConnectionClosed
to indicate that to client code.write_pending
What causes this I think is that there is no state in
WebSocketState
to indicate the close handshake is finished when the remote initiated it.CloseAcknowlegded
is only used when we initiated. We know that when we received an initial close frame from the remote, we will have cued a reply so this kind of bumps it to terminated, but only for server role.It doesn't really make sense to have
CloseAcknowlegded
only count when we initiated the close handshake. The websocket protocol mainly distinguishes a state when the handshake is finished, regardless of who initiated it. I think it's just the way it is because given the design of tungstenite, it's kind of hard to do this right. We know when we cue a close response, but we never know when we actually sent it out. It seems not easy to fix this without creating extra overhead on each call to write_pending, similar to how it's done for pong messages for example.There is a few problems:
AlreadyClosed
claims that you will getAlreadyClosed
if you try to send after receiving aMessage::Close
. For servers we can see here that we will actually returnConnectionClosed
if the user tries to send after receiving a close. Integration test: already_closed.rs.txt.ConnectionClosed
to soon, because we shouldn't drop the underlying connection yet.The text was updated successfully, but these errors were encountered: