Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Type
Test/Question/Other
PR Checklist
Overview
This PR emphasises my question regarding proper behavior of
WebSocket
close procedure.It seems like neither receiving close and sending it back to client nor initiating close and receiving it back from client (close handshake) does not cause web socket stream to finish and TCP connection released.
I'm not sure if it's my expectation from API is wrong or there is a bug. But anyway the question is what is the proper way to terminate WebSocket (except
ctx.stop()
which seems to terminate connection ungracefully, possibly loosing pending messages)?I've inspected code and it seems like there are some parts which are intended to do some special handling of web socket closure, but this code seems to be never executed. E.g. there is
Message::Close
with single usage acrossactix-web
repo, so it's not created anywhere:actix-web/actix-http/src/ws/dispatcher.rs
Lines 357 to 360 in ff8fd2f
There is also some code within
WebsocketContextFut
to markWebSocket
as closed, which marks WS as closed whenNone
is read frommessages
queue:actix-web/actix-web-actors/src/ws.rs
Lines 703 to 710 in ff8fd2f
while there is no possibly to write
None
to outgoing messages queue:actix-web/actix-web-actors/src/ws.rs
Lines 605 to 638 in ff8fd2f
The only part of close which seems to work as expected is when underlying connection is closed by client app and handled here:
actix-web/actix-web-actors/src/ws.rs
Lines 769 to 784 in ff8fd2f
So maybe maintainers could kindly provide answers to questions I've raised here: