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
WebSocket created during close of a previous one is never closed #3935
Labels
bug
Confirmed bug
Comments
maknapp
added a commit
to maknapp/rxjs
that referenced
this issue
Dec 6, 2021
The close event on WebSocket does not always occur immediately after running the close function. If the close event is occurs after a new WebSocket is opened, then the reset needs to be skipped. This checks to make sure the socket being reset is the one that matches the event. Closes ReactiveX#4650, ReactiveX#3935
benlesh
pushed a commit
that referenced
this issue
Dec 6, 2021
The close event on WebSocket does not always occur immediately after running the close function. If the close event is occurs after a new WebSocket is opened, then the reset needs to be skipped. This checks to make sure the socket being reset is the one that matches the event. Closes #4650, #3935 Co-authored-by: Mark Knapp <mknapp@leightronix.com>
benlesh
pushed a commit
that referenced
this issue
Dec 6, 2021
The close event on WebSocket does not always occur immediately after running the close function. If the close event is occurs after a new WebSocket is opened, then the reset needs to be skipped. This checks to make sure the socket being reset is the one that matches the event. Closes #4650, #3935 Co-authored-by: Mark Knapp <mknapp@leightronix.com>
@benlesh This issue can be closed. (I used the wrong format to auto-close in the commit.) |
1 task
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Current Behavior
When there are no more subscriptions to a
WebSocketSubject
, then the underlyingWebSocket
is closed. If you then create a new subscription on theWebSocketSubject
, before theonclose
of the previousWebSocket
has fired, then the newly createdWebSocket
will never be closed.If you combine this with the
multiplex
function, then some subscribe/unsubscribe messages will not be send as well.Reproduction
WebSocketSubject
WebSocketSubject
https://stackblitz.com/edit/typescript-n7jv6k
In case the stackblitz does not work, here is the code it contains:
Show imports and utility class
I would expect the log to show the following, but the lines with the strike-through are missing:
Created socket 0
Opened socket 0
Socket 0 sends: "sub0.1"
Socket 0 sends: "sub0.2"
Socket 0 sends: "unsub0.1"
Socket 0 sends: "unsub0.2"
Closing socket 0
Created socket 1
Closed socket 0
Opened socket 1
Socket 1 sends: "sub1.1"Socket 1 sends: "sub1.2"Socket 1 sends: "unsub1.1"
Socket 1 sends: "unsub1.2"Closing socket 1Created socket 2
Closed socket 1Opened socket 2
Socket 2 sends: "sub2.1"
Socket 2 sends: "sub2.2"
Socket 2 sends: "unsub2.1"
Socket 2 sends: "unsub2.2"
Closing socket 2
Complete
Closed socket 2
Expected behavior
I expect all websockets to be closed in the end, and that all subscribe/unsubscribe messages are send.
Environment
Possible Solution
I did a little digging, and the problem is caused by
_resetState
being called twice withinWebSocketSubject
, when closing the first websocket. The first time it is called from the last unsubscribe (anonymous function inside_subscribe
), and a second time fromsocket.onclose
. The problem with that is that the second websocket has already been created, when theonclose
of the first websocket fires. One possible solution is to add the following check around the_resetState
call insidesocket.onclose
:The text was updated successfully, but these errors were encountered: