Skip to content
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

Merged
merged 2 commits into from
Nov 24, 2024

Conversation

sirkrypt0
Copy link
Contributor

@sirkrypt0 sirkrypt0 commented Jul 16, 2024

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.

@MnlPhlp
Copy link

MnlPhlp commented Aug 13, 2024

Are there any remaining problems with this?
This looks like it solves exactly what I need.

Copy link
Collaborator

@ctrlaltf24 ctrlaltf24 left a 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")
Copy link
Collaborator

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

Copy link
Contributor Author

@sirkrypt0 sirkrypt0 Sep 22, 2024

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.

@sirkrypt0 sirkrypt0 force-pushed the feature/notify-on-unknown-disconnect branch 3 times, most recently from 6d21908 to 8605ca8 Compare September 22, 2024 16:59
Copy link
Collaborator

@ctrlaltf24 ctrlaltf24 left a 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?

ci/socket-io.js Outdated Show resolved Hide resolved
socketio/src/asynchronous/client/client.rs Outdated Show resolved Hide resolved
socketio/src/event.rs Outdated Show resolved Hide resolved
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.
@sirkrypt0 sirkrypt0 force-pushed the feature/notify-on-unknown-disconnect branch from 8605ca8 to 0540579 Compare September 24, 2024 08:20
Copy link
Collaborator

@ctrlaltf24 ctrlaltf24 left a 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

Copy link
Owner

@1c3t3a 1c3t3a left a 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!

@1c3t3a 1c3t3a merged commit cf9e93e into 1c3t3a:main Nov 24, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async client is not notified of (unexpected) websocket transport close
4 participants