-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Start the client WebSocket closing timeout after sending the close frame #5609
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
Start the client WebSocket closing timeout after sending the close frame #5609
Conversation
|
@vietj this code resolves #5592 but introduces a small concern: it is not possible to determine if the connection was closed normally within the close handler since the close status is set to the status of the initial frame in the closing handshake. I suppose this is an entirely separate issue, but thought I would point it out. Perhaps we should avoid firing the close handler if a close frame was not received? |
that's a good point, we can use the status code 1006 to indicate that : Abnormal Closure |
|
@emattheis I think actually it does not apply to this case because the client initiates the close operation and provides a status code. The server should respond with a close frame that is an echo of the client sent close frame so the status should be the same value as provided by the client that initiated the closure. |
5dde6a4 to
ce8502c
Compare
This gets tricky, though, because the sent and received close frames should always match. We don't want to misrepresent what went over the wire. Per the Vert.x API the close status and reason should be |
|
@emattheis the main difference with the normal case is that vertx end handler will not be called and instead the exception handler will be |
|
@emattheis what you are saying kind of makes sense too, but changing that would be breaking with users expecting a status code not null |
|
I think the only case then is to use status code 1006 instead which signals this case instead |
…ame. Motivation: When closing a client WebSocket, the client sends a close frame and expects the server to respond with a close frame and then close the connection. Some servers can misbhave by ignoring the close frame and this let the client deal with the socket. The client has a closing timeout which handle the case where the server responds with a close frame but does not actually close the connection. The timeout can be extended to handle the case where the server does not send a close frame. Changes: Start the closing timeout after sending succesfully the close frame instead of upon reception of the server close frame. When a WebSocket closes without receiving a close frame, the WebSocket status code is the value 1006 (per https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5)
ce8502c to
f5b69e8
Compare
|
@emattheis I updated the code with the usage of 1006 (https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5) |
Personally, I think this is more confusing, because we have no way to tell if that was actually the closure code set by the client or the server or Vert.x. At least in the current release we know the code was set (explicitly or implicitly) by calling On the other hand, I guess if I really want to know if the close frame was received from the remote endpoint I can register an exception handler and look for the closed exception, so it won't matter if the status code is changed by Vert.x. |
Motivation:
When closing a client WebSocket, the client sends a close frame and expects the server to respond with a close frame and then close the connection.
Some servers can misbehave by ignoring the close frame and this let the client deal with the socket.
The client has a closing timeout which handle the case where the server responds with a close frame but does not actually close the connection.
The timeout can be extended to handle the case where the server does not send a close frame.
Changes:
Start the closing timeout after sending successfully the close frame instead of upon reception of the server close frame.