Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

WebSocket connection is closed without proper handshake #77

@mkosieradzki

Description

@mkosieradzki

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

Metadata

Metadata

Assignees

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