SignalR Websocket Exception when closing client

dsfgsho picture dsfgsho · Feb 25, 2015 · Viewed 9k times · Source

When starting and stopping a SignalR client that is connected to a basic self hosted server like this:

async public void Start(string url)
{
    _connection = new HubConnection(url);
    _proxy = _connection.CreateHubProxy("hubname");
    await _connection.Start().ContinueWith((task) => IsRunning = true);
}
public void Stop()
{
    _connection.Stop();
}

I get the following exception when calling the "Stop" method (including trace messages):

SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(c75fe282-a86d-406a-935b-5981b47bd472)
SignalR.Transports.TransportHeartBeat Information: 0 : Connection 1bdabc19-e0a7-4649-aabb-bade071ad6d0 is New.
SignalR.Transports.WebSocketTransport Information: 0 : Abort(1bdabc19-e0a7-4649-aabb-bade071ad6d0)
SignalR.Transports.TransportHeartBeat Information: 0 : Removing connection 1bdabc19-e0a7-4649-aabb-bade071ad6d0
SignalR.Transports.WebSocketTransport Information: 0 : End(1bdabc19-e0a7-4649-aabb-bade071ad6d0)
SignalR.Transports.WebSocketTransport Verbose: 0 : DrainWrites(1bdabc19-e0a7-4649-aabb-bade071ad6d0)
SignalR.Transports.WebSocketTransport Information: 0 : CloseSocket(1bdabc19-e0a7-4649-aabb-bade071ad6d0)
App.vshost.exe Error: 0 : Error while closing the websocket: System.Net.WebSockets.WebSocketException (0x80004005): An internal WebSocket error occurred. Please see the innerException, if present, for more details.  ---> System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.WebSockets.WebSocketConnectionStream.WebSocketConnection.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Net.WebSockets.WebSocketConnectionStream.<WriteAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.<SendFrameAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.WebSocketOperation.<Process>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.<CloseOutputAsyncCore>d__17.MoveNext()
   at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
   at System.Net.WebSockets.WebSocketBase.<CloseOutputAsyncCore>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<<CloseAsync>b__6>d__8.MoveNext()
App.vshost.exe Error: 0 : Error while closing the websocket: System.Net.WebSockets.WebSocketException (0x80004005): An internal WebSocket error occurred. Please see the innerException, if present, for more details.  ---> System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
   at System.Net.WebSockets.WebSocketConnectionStream.WebSocketConnection.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at System.Net.WebSockets.WebSocketConnectionStream.<WriteAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.<SendFrameAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.WebSocketOperation.<Process>d__47.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.WebSocketBase.<CloseOutputAsyncCore>d__17.MoveNext()
   at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
   at System.Net.WebSockets.WebSocketBase.<CloseOutputAsyncCore>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<<CloseAsync>b__6>d__8.MoveNext()
SignalR.Transports.WebSocketTransport Information: 0 : CompleteRequest (1bdabc19-e0a7-4649-aabb-bade071ad6d0)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(c75fe282-a86d-406a-935b-5981b47bd472)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(c75fe282-a86d-406a-935b-5981b47bd472)

The setups itself seem to work fine and devices can connect, send, receive, and disconnect. But with every disconnect I get the ugly above exception. Any idea what the problem could be? I am using SignalR 2.2.0 and Owin 1.2.2.

Answer

Miha Markic picture Miha Markic · Mar 25, 2015

Looks like a known issue which might be fixed in v3.