pusher / pusher-websocket-dotnet

Pusher Channels Client Library for .NET
MIT License
112 stars 113 forks source link

NRE caused by race between Disconnect and automatic reconnect #73

Closed cdauphinee closed 4 years ago

cdauphinee commented 5 years ago

When the socket is closed externally (i.e. from the remote side closing the connection), the websocket_Closed will dispose/null out the socket, sleep, and try to reconnect.

If a call to Disconnect comes in during the sleep, it will encounter an NRE when it tries to call Close on the null socket, and then the sleeping thread will continue and re-connect the socket.

I can reproduce this fairly consistently in Unity by trying to connect with an invalid key, which seems to make the server close the connection, and then signaling another thread to call DisconnectAsync in the Error event handler.

image