Closed
Description
From @seijikun on Sunday, May 29, 2016 10:42:26 AM
Title
Connection always aborts with CLOSE_ABNORMAL(1006) with WebKit-Browsers.
Functional impact
The client can not receive the sent WebSocketCloseStatus
-Codes since the connection always seems to be aborted, whereupon the browser returns the StatusCode CLOSE_ABNORMAL(1006)
.
Minimal repro steps
- Scaffold a new rc1-final Web-API project (I can not use rc2 since my linux distro is not supported yet).
- Add the missing dependency to the
project.json
:
"Microsoft.AspNet.WebSockets.Server": "1.0.0-rc1-final"
- Replace the code in Startup.cs with the following (mostly copied from TestServer):
using System;
using System.Net.WebSockets;
using System.Threading;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Extensions.Logging;
namespace wsTest
{
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseWebSockets();
app.Use(async (context, next) =>
{
if (context.WebSockets.IsWebSocketRequest)
{
var client = await context.WebSockets.AcceptWebSocketAsync();
byte[] buffer = new byte[1024];
WebSocketReceiveResult received = await client.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
while (received.MessageType != WebSocketMessageType.Close)
{
await client.SendAsync(new ArraySegment<byte>(buffer, 0, received.Count), received.MessageType, received.EndOfMessage, CancellationToken.None);
received = await client.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
}
await client.CloseAsync(received.CloseStatus.Value, received.CloseStatusDescription, CancellationToken.None);
}
});
}
public static void Main(string[] args) => Microsoft.AspNet.Hosting.WebApplication.Run<Startup>(args);
}
}
- Run the server
- Open a Webkit-Based browser's Developer Tools window, go to the console and paste the following:
var handler = function(){console.log(arguments);};
var test = new WebSocket('ws://localhost:5000');
test.onclose = handler;
test.onopen = handler;
test.onerror = handler;
test.onmessage = handler;
now try:
test.close();
Expected result
The connection should be normally closed with the code CLOSE_NORMAL(1000)
.
Actual result
The connection is aborted, and the CloseEvent
(which is logged to the Browser-Console in the example) shows the code
: CLOSE_ABNORMAL(1006)
.
Misc Info
- Operating System: Linux OpenSUSE Tumbleweed
- Tested browsers:
Opera-37.0.2178.32
,Chromium-50.0.2661.102
,Firefox-46.0
. - Works fine with tested Firefox.
Did I do something wrong in the code?
Copied from original issue: aspnet/WebSockets#86