Consider following server code:
app.UseWebSockets().Run(async ctx =>
{
var socket = await ctx.WebSockets.AcceptWebSocketAsync();
await socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
var buffer = new byte[4096];
await socket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
});
running through: IISIntegration, Kestrel and IISExpress (VS2017 RC)
When a client connects: server uses CloseOutputAsync to start connection close handshake.
Client receives proper close message and is obligated to complete Close handshake using CloseOutputAsync as well:
https://tools.ietf.org/html/rfc6455#section-1.4 states:
Upon receiving such a frame, the other peer sends a Close frame in response, if it hasn't already sent one.
But the AspNetCoreModule kills the underlying TCP connection instead. And socket.ReceiveAsync which would expect receiving MessageType.Close, throw exception instead:
System.Net.WebSockets.WebSocketException: 'The remote party closed the WebSocket connection without completing the close handshake.'
Just for reference Client code:
await client.ConnectAsync(new Uri("ws://localhost:5300/test"), CancellationToken.None);
var buffer = new byte[4096];
var res = await client.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
//Following code does not matter at all as here connection is already dead