Skip to content

OnError, Reconnect not called when Receive throws an exception #23

@lheinold

Description

@lheinold

I am testing unexpected disconnects and sometimes the following happens:

Exception thrown: 'System.IO.IOException' in System.Net.Sockets.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
2019-09-13T09:41:05.9454580+02:00 PureWebSocket.StartListener: Receive threw an exception: The remote party closed the WebSocket connection without completing the close handshake.
2019-09-13T09:41:05.9471401+02:00 PureWebSocket.StartListener: Listener exiting

Poking through the code I found:

_logger.Log($"Receive threw an exception: {ex.Message}");
// Most likely socket error
 _reconnectNeeded = true;
 _ws.Abort();
break;

I believe that this should invoke OnError and trigger a reconnect (it looks like after listener exits no other tasks are executed, so it doesn't matter if _reconnectNeeded is true). It might also be helpful to rethrow so the client can catch the exception (currently I have no way of telling if this error occurs)

I think this has something to do with the fact that if the monitor loop does not exit properly (like on a break) _isMonitorRunnning continues to be true and the monitor never restarts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions