radu-matei / websocket-manager

Real-Time library for ASP .NET Core
https://radu-matei.com/blog/real-time-aspnet-core/
MIT License
452 stars 182 forks source link

WebSocketManagerMiddleware class throws Websocket Exception when the socket is not properly closed #42

Open viniciap opened 7 years ago

viniciap commented 7 years ago

I've been struggling to find this problem for the past 24 hours.

In the WebSocketManagerMiddleware class, the awaitable Receive Task will throw an unhandled Websocket Exception that will break the application in the case of a socket not being properly closed. The ExceptionHandlerMiddleware was unable to catch it as well, not sure why.

The exact message is something like "The remote party closed the WebSocket connection without completing the close handshake."

This can probably be replicated using the mvc sample, then using a cellphone to connect to the websocket and then switching back to another process so the browser will be in background.

mihai-burduselu commented 7 years ago

I read something about this problem and I modified the method of closing the socket. I put the changes in a new branch at this link. @v1n1akabozo, please switch to this branch, test it and tell me if the bug still persists.

viniciap commented 7 years ago

@mihai-burduselu

I'll give it a try soon. What i did this morning was to remove the nuget dependency, use the original source and then handle all possible exceptions and now my application is stable.

radu-matei commented 7 years ago

Unfortunately, the NuGet is based on a lower version of the repo (that in the meantime has been updated). Take a look at the current version, at the fix @mihai-burduselu made and if you still handle additional exceptions, please submit a pull request.

Thanks!