SignalR Websocket Exception when closing client

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.

Thanks!


看起来像一个已知问题,可能在v3中得到修复。


我发现,当我将TimeSpan提供给close方法时,这种异常不会发生。

public void Stop()
{
    _connection.Stop(new TimeSpan(1000))
}

Ok guys, I know its lame. I am trying to shutdown signalr client when the mainwindow closes and I get a lot of exceptions that I can not catch and my process hangs. So i decided to kill the main process on form close.

private void OnClose(object sender, CancelEventArgs e){
        try
        {
            var process = Process.GetCurrentProcess();
            process.Kill();
            //HubConnection.Stop();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }

}
链接地址: http://www.djcxy.com/p/84024.html

上一篇: jquery通过xpath选择元素

下一篇: 关闭客户端时SignalR Websocket异常