Fix ClientWebSocket closing handshake logic (dotnet/corefx#36975)
authorDavid Shulman <david.shulman@microsoft.com>
Thu, 18 Apr 2019 03:33:23 +0000 (20:33 -0700)
committerGitHub <noreply@github.com>
Thu, 18 Apr 2019 03:33:23 +0000 (20:33 -0700)
commitc28ecfa2bf707c7b8ce64efce2c61f528fcd8315
tree6d79b8f4485854a5755f5c8b79491b73559bfe5e
parent69f7ecb4dacaa0983126ca1e24f465afd0531e63
Fix ClientWebSocket closing handshake logic (dotnet/corefx#36975)

An HttpListener websocket test was failing after the change from PR dotnet/corefx#36928. That PR made changes
to tighten up the transition to the Closed state after the closing handshake had completed.

That PR missed some additional changes needed especially in cases where a server (such as loopback)
sends the close frame almost concurrently with the client sending the close frame.

This PR fixes the close frame handshake logic and also makes some optimizations in cases where the
websocket has already transitioned to the Aborted state during the closing handshake. In that case,
the websocket should not wait for a close frame to be received but should simply proceed to closing
the connection.

Fixes dotnet/corefx#36963

Commit migrated from https://github.com/dotnet/corefx/commit/1824535f95defea3ba464599ee4b9937a82eaaf9
src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs
src/libraries/System.Net.HttpListener/tests/HttpListenerWebSocketTests.cs