You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current Behavior
When there are no more subscriptions to a WebSocketSubject, then the underlying WebSocket is closed. If you then create a new subscription on the WebSocketSubject, before the onclose of the previous WebSocket has fired, then the newly created WebSocket will never be closed.
If you combine this with the multiplex function, then some subscribe/unsubscribe messages will not be send as well.
Reproduction
Create WebSocketSubject
Create two subscriptions on WebSocketSubject
Wait a second
Unsubscribe both subscriptions and immediately create two new ones
Expected behavior
I expect all websockets to be closed in the end, and that all subscribe/unsubscribe messages are send.
Environment
Runtime: Chrome v67.0.3396.99
RxJS version: 6.2.2
Possible Solution
I did a little digging, and the problem is caused by _resetState being called twice within WebSocketSubject, when closing the first websocket. The first time it is called from the last unsubscribe (anonymous function inside _subscribe), and a second time from socket.onclose. The problem with that is that the second websocket has already been created, when the onclose of the first websocket fires. One possible solution is to add the following check around the _resetState call inside socket.onclose:
if(this._socket===e.target){this._resetState();}
The text was updated successfully, but these errors were encountered:
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.
ClosesReactiveX#4650, ReactiveX#3935
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>
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>
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: