-
Notifications
You must be signed in to change notification settings - Fork 83
fix(async): handle close of packet stream to avoid panic #324
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
When the packet stream closes, e.g. because the server terminated the connection, the stream returns None. Then, the next() function shouldn't be called again on the stream, as it is already closed. Previously, we wouldn't handle this, which lead to a panic. Before the fix which implemented the as_stream() function for the socket, the program wouldn't panic, but instead run in an endless loop which isn't ideal either. Now, the loop which fetches the packets from the stream properly terminates. However, the program which uses the socket.io client currently isn't notified of the unexpected closure.
Codecov Report
@@ Coverage Diff @@
## main #324 +/- ##
==========================================
+ Coverage 90.94% 91.01% +0.06%
==========================================
Files 37 37
Lines 4673 4672 -1
==========================================
+ Hits 4250 4252 +2
+ Misses 423 420 -3
|
First of all thanks for the PR! I appreciate your contributions to the async version of the crate a lot, the stream impl isn't perfect, but IMO currently the best to do in async rust.
Do you think it makes sense to add this feature for tests only? That case we can verify to not brake it and only add a dependency for devs and not for normal users of the crate.
Yes, and this is an issue (also see the opened issues around it). Do you have an idea how to fix this (e.g. invoke the err callback or something else?). We can't invalidate a |
I totally agree that it would make sense to test this and tried it out here https://github.com/giz-berlin/rust-socketio/blob/fix/async-stream-close-test/socketio/src/asynchronous/client/client.rs#L555-L603 [target.'cfg(test)']
# Rustflags specifically for tests
rustflags = ["--cfg", "tokio_unstable"] See rust-lang/cargo#8170. Instead I enabled it via the Let me know what you think :) |
Calling the I think the use of the rust-socketio/socketio/src/client/raw_client.rs Lines 377 to 386 in 39297a5
So maybe, the Additionally, it may be useful to have a separate |
+1 This sounds like a feasible approach, can you maybe create an issue for when to remove it and add a doc comment? I think it's just good if those tests actually run.
Yeah this isn't optimal. I think parsing the error is the worst approach to take here, so the
I agree with you here. Maybe we can split the error enum to errors that we want to expose and internal errors that don't matter to the user but only to us. Also +1 to the I hope to find time to work on this the upcoming weeks, if not, feel free to pick something up! :) And thanks for the your comments here! |
When the packet stream closes, e.g. because the server terminated the connection, the stream returns None. Then, the next() function shouldn't be called again on the stream, as it is already closed.
Previously, we wouldn't handle this, which lead to a panic.
Before the fix which implemented the as_stream() function for the socket, the program wouldn't panic, but instead run in an endless loop which isn't ideal either.
Now, the loop which fetches the packets from the stream properly terminates. However, the program which uses the socket.io client currently isn't notified of the unexpected closure.
Closes #323
While I tried writing a test for this, it appears that you can't assert whether some tokio thread panicked or not without having the handle to that thread (there is a feature in
tokio_unstable
calledunhandled_panic
though).Since the builder currently spawns the stream iterator without returning a handle, I didn't find a way to properly assure the this thread doesn't panic.