Skip to content
This repository has been archived by the owner on Oct 18, 2018. It is now read-only.

ReceiveAsync cancellation throws WebSocketException and terminates the socket #68

Closed
zeroskyx opened this issue Jan 6, 2016 · 2 comments

Comments

@zeroskyx
Copy link

zeroskyx commented Jan 6, 2016

await Socket.ReceiveAsync( new ArraySegment( Buffer ), Ct );
cannot be cancelled on a ClientWebSocket when Ct is the CancellationToken.
Instead of throwing a OperationCanceledException and keeping the socket alive, the following exception is thrown and the socket is aborted:

System.Net.WebSockets.WebSocketException: The 'System.Net.WebSockets.InternalClientWebSocket' instance cannot be used for communication because it has been transitioned into the 'Aborted' state. ---> System.Net.Http.WinHttpException: The operation has been canceled

This is true for both the ClientWebSocket and on a server socket when WebListener is used.
When Kestrel is used, ReceiveAsync CAN be cancelled on the SERVER, the cancellation takes about 10 seconds though.

Minimal solution with both the client and server part to reproduce on Stack Overflow: http://stackoverflow.com/questions/34634652/dnx-core-websocket-clientwebsocket-receiveasync-cancellation-is-not-working-p

@davidfowl
Copy link
Member

This looks like it's the ClientWebSocket implementation on windows. This issue belongs on https://github.com/dotnet/corefx/issues

@muratg
Copy link

muratg commented Jan 12, 2016

This issue was moved to dotnet/corefx#5340

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants