-
Notifications
You must be signed in to change notification settings - Fork 81
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
feat(socketio): notify client of transport completion #449
feat(socketio): notify client of transport completion #449
Conversation
Are there any remaining problems with this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: would be nice to have a test for this before merging @sirkrypt0
// We don't need to do that in the other cases, since proper server close | ||
// and manual client close are handled explicitly. | ||
if let Some(err) = client_clone | ||
.callback(&Event::Close, "transport close") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: constant for this message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new CloseReason
enum and used the appropriate values wherever the Event::Close
was emitted. This should make it more consistent and easier for clients to distinguish the close reasons.
I'm not sure if the event.rs
file is the correct location for that, but since it's closely related to the Event::Close
I thought it may be fitting.
6d21908
to
8605ca8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@1c3t3a this ready to merge?
When the async client connects to the server, it spawns a new thread to handle the arriving messages asynchronously, which is immediately detached with no chance of awaiting its completion. For long-running programs (e.g. a client program that never really disconnects from the server) this can be problematic, as unexpected stream completions would go unnoticed. This may happen if the underlying tungstenite websocket shuts down ('Received close frame: None') but there are no engineio/socketio close frames. Hence, since the stream terminates, the message handling task stops without a Close or Error event being fired. Thus, we now fire an additional Event::Close when the stream terminates, to signal the (potentially unexpected) close to the user.
Previously, when we emitted an Event::Close, we didn't specify a reason for why this event was emitted. When implementing the close notification on unexpected transport closes, we started sending 'transport close' as the payload for the close event. We now decided to do this more consistently and added a close reason when emitting the Event::Close, so that the client better knows why this event was emitted.
8605ca8
to
0540579
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still waiting on @1c3t3a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM! Sorry for the delay!
When the async client connects to the server, it spawns a new thread to handle the arriving messages asynchronously, which is immediately detached with no chance of awaiting its completion.
For long-running programs (e.g. a client program that never really disconnects from the server) this can be problematic, as unexpected stream completions would go unnoticed. This may happen if the underlying tungstenite websocket shuts down ('Received close frame: None') but there are no engineio/socketio close frames. Hence, since the stream terminates, the message handling task stops without a Close or Error event being fired.
Thus, we now fire an additional Event::Close when the stream terminates, to signal the (potentially unexpected) close to the user.
Closes #448
Once we settle on a final solution, I can also write a test for that.