The traces from our functional tests show that the server websocket transport is throwing an exception when the .NET client stops the connection.
ProcessInvocation86.exe Information: 0 : Created new iis express instance. PID 13764
ProcessInvocation86.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.DelegatedStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketConnectionStream.<>n__FabricatedMethod14(Byte[] , Int32 , Int32 , CancellationToken )
at System.Net.WebSockets.WebSocketConnectionStream.
--- 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.
--- 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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.
--- 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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Net.WebSockets.WebSocketBase.
at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
at System.Net.WebSockets.WebSocketBase.
--- 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.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<
ProcessInvocation86.exe Information: 0 : IISExpressTestHost.Dispose()
ProcessInvocation86.exe Information: 0 : IISExpressTestHost.Shutdown()
ProcessInvocation86.exe Information: 0 : IISExpress exited
ProcessInvocation86.exe Information: 0 : Killed iisexpress PID 13764.
SignalR.Transports.TransportHeartBeat Information: 0 : Connection 66524093-dca2-45b3-8aa8-17db0cf781ac is New.
SignalR.Transports.WebSocketTransport Information: 0 : Abort(66524093-dca2-45b3-8aa8-17db0cf781ac)
SignalR.Transports.TransportHeartBeat Information: 0 : Removing connection 66524093-dca2-45b3-8aa8-17db0cf781ac
SignalR.Transports.WebSocketTransport Information: 0 : End(66524093-dca2-45b3-8aa8-17db0cf781ac)
SignalR.Transports.WebSocketTransport Verbose: 0 : DrainWrites(66524093-dca2-45b3-8aa8-17db0cf781ac)
SignalR.Transports.WebSocketTransport Information: 0 : CompleteRequest (66524093-dca2-45b3-8aa8-17db0cf781ac)
SignalR.Transports.WebSocketTransport Information: 0 : CloseSocket(66524093-dca2-45b3-8aa8-17db0cf781ac)
06:09:21.5601058 - null - ChangeState(Disconnected, Connecting)
06:09:22.5741589 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS Connecting to: ws://localhost:1337/signalr/connect?transport=webSockets&connectionToken=/EMhQFmuw8HOI1L7ZhvCa65tF3qywdodaCBMvR3YJOhy+jHDkxug5gpgEK8uCVrnPbI3EZv8Uzu9UEhCnMKtxhiyJO2rWzbYIWFcbKskP7V2zhJbo/UK7LF/YTgqmbFu&connectionData=[{"Name":"OnConnectedBufferHub"}]&test=HubProxyFacts.TransportsQueueIncomingMessagesCorrectly.2&pid=13764
06:09:24.7552831 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnMessage({"C":"d-3D3359E9-B,0|C,2|D,1|E,0","M":[{"H":"OnConnectedBufferHub","M":"bufferMe","A":[0]}]})
06:09:24.8002892 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnMessage({"C":"d-3D3359E9-B,0|C,2|D,1|E,0","M":[{"H":"OnConnectedBufferHub","M":"bufferMe","A":[1]}]})
06:09:24.8012867 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnMessage({"C":"d-3D3359E9-B,0|C,2|D,1|E,0","S":1,"M":[]})
06:09:24.8032875 - 66524093-dca2-45b3-8aa8-17db0cf781ac - ChangeState(Connecting, Connected)
06:09:24.8792911 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnMessage({"C":"d-3D3359E9-B,0|C,3|D,1|E,0","M":[{"H":"OnConnectedBufferHub","M":"pong","A":[]}]})
06:09:24.8852903 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnMessage({"I":"0"})
06:09:24.8902920 - 66524093-dca2-45b3-8aa8-17db0cf781ac - Stop
06:09:24.9552961 - 66524093-dca2-45b3-8aa8-17db0cf781ac - WS: OnClose()
06:09:24.9562963 - 66524093-dca2-45b3-8aa8-17db0cf781ac - Disconnected
06:09:24.9562963 - 66524093-dca2-45b3-8aa8-17db0cf781ac - Transport.Dispose(66524093-dca2-45b3-8aa8-17db0cf781ac)
06:09:24.9662971 - 66524093-dca2-45b3-8aa8-17db0cf781ac - Closed
@halter73 can you look a this?
@davidfowl, this is happen to me too. In my test rig I've set a 20 sec timeout in the call to Stop() -> no change. It doesn't seem to matter if I have 1 client or 1200.
Also it takes ten times longer to shut down the clients that it does to start them. I suspect this has a lot to do with the lack of an awaitable Stop.
Merry Christmas.
Scott
We'll move this to the new repo as a candidate for v3 or beyond.
Is there a link to the v3 backlog item for this task?
Still throws an exception after client disconnect using self-hosted SignalR...The latest version of SignalR was installed from the NuGet. Any chances to make it work? Sample project => https://cloud.mail.ru/public/3Pb2/GNRUxtk8Z
Any solution for c# ?
@shelland and @DamianEdwards I also see this happen in Self-hosted. Any workaround ? Or possible solution for this ?
@ClientIco - older version (v2) doesnt throw such exceptions. I've downgraded to the older version using NuGet and it looks like that it works correctly. Waiting for the fix for this version
Yes I also get this error on client disconnect (also self-hosted in a service)
@shelland Which v2 version exactly?
According to nuget https://www.nuget.org/packages/Microsoft.AspNet.SignalR/2.2.0
latest is 2.2.0
ibiza240 - yes, try this (2.2.0) version
@shelland ok I have this version and the bug occuring...
@ibiza240 try this sample (https://yadi.sk/d/GdSMo4F_hXU85) - it works great for me.
This happens also by us. This prevent us from using websockets on win10 clients.
Works ok on win7 as server sent event is used instead of websockets.
Currently used version: 2.2
Execption is thrown when trying to dispose the hubconnection signalr .net client object:
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.DelegatedStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketConnectionStream.<>n__1(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at System.Net.WebSockets.WebSocketConnectionStream.<WriteAsync>d__22.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__48.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__19.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__51.MoveNext()
at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
at System.Net.WebSockets.WebSocketBase.<CloseOutputAsyncCore>d__51.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.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Microsoft.AspNet.SignalR.TaskAwaiterHelper.PreserveCultureAwaiter.GetResult()
at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<<CloseAsync>b__6>d__8.MoveNext()
I also get this error
I am using SignalR version 2.2 and i am having the same exceptions on server and not on local server. The SignalR works for 5 to 10 minutes and then below exceptions start logging. Any help will be appreciated.
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.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketConnectionStream.d__c.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.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at System.Net.WebSockets.WebSocketBase.WebSocketOperation.
at Microsoft.AspNet.SignalR.WebSockets.WebSocketMessageReader.d__0.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.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.d__e.MoveNext()
ExecutionContext.Run => ExecutionContext.RunInternal => d__e.MoveNext
+1
is this resolved?
There might be multiple causes causing this exception.
We also have self-hosted signalr. Used websockets by default and got this exception. Switched to long pooling and got another problem - when client suddenly losing connection to server and fails to restore it until browser page refreshed and new client_id generated.
@zombinome - when you refresh your page you are starting a new connection and therefore you get a new connection id. The way to go about this exception is to understand why the server (or something between the server and the client) closed it. There is nothing SignalR can do if the server closes the connection. With websockets one of the reason the server can close the connection is when the client sends a message that is bigger that the maximum allowed size. By default the maximum allowed size is 64KB and if you don't change it but happen to send messages bigger than 64KB the server will close the connection. Other exceptions happening on the server side may close the connection as well.
so,It's resolved?
I am also facing the same issue. I am creating a signalr connection to a hub from a WPF application. On calling connection.Stop or connection.Dispose i see the exceptions in console. Using version 2.2.2.0 of Microsoft.AspNet.SignalR.Client.
I'm using 2.2.3 and the same problem happens
Not resolved as of yet. I connect to a server, get a piece of data, then run client.Stop() (w/ or w/o timeout). I just used NuGet to update to SignalR 2.4, i'm using .NET Framework 4.7.1. Everything works--the server and client exchange data just fine--I just get this error message dumped to my console (I'm using TopShelf to create a Windows Service) and I can't catch the exception or stop the output. Just have to live with it until it's cleaned up, I guess.
Edit: another observation--if I open and close the client in my "client" app, it works just fine, no error. If I do so from an app that's hosting a SignalR server (acting as the client to another server) I get this error. Implies that the client code has state information that collides with server state code.
We still encounter this exception with win7, win8 and win10 clients using owin, signalr2.4 with only websockets enabled, no fallback protocol. We believe the exceptions are causing the entire app to crash after a period of time with an clr.dll appcrash exception. Here is what we log on the client:
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.
here is what we logon on the server:
SignalR.Transports.WebSocketTransport Error: 0 : OnError(6eecc47e-1e17-4e1f-9ba5-83460a988118, System.Net.WebSockets.WebSocketException (0x80004005): An internal WebSocket error occurred. Please see the innerException, if present, for more details. ---> System.Net.HttpListenerException (0x80004005): The I/O operation has been aborted because of either a thread exit or an application request
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.WebSockets.WebSocketHttpListenerDuplexStream.
--- 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.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Net.WebSockets.WebSocketBase.WebSocketOperation.
--- 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.
at System.Net.WebSockets.WebSocketBase.ThrowIfConvertibleException(String methodName, Exception exception, CancellationToken cancellationToken, Boolean aborted)
at System.Net.WebSockets.WebSocketBase.
--- 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.WebSocketMessageReader.
--- 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.
@clifton-collins3iii A SocketException (0x80004005)
should not crash the entire app. If you are still having a problem, can you please open a new GitHub issue with details about the "clr.dll appcrash exception"? Thanks.
@clifton-collins3iii I have exactly the same problem as you ! On Windows 10 with server OWIN 3.1.0 and client Microsoft.AspNet.SignalR.Client 2.2.2. I still do not have a solution.
To resolve put in a timeout to allow the operation to shutdown properly:
HubConnection?.Stop(new TimeSpan(1000));
The default timeout if you pass in no parameters is already 30 seconds.
All I know is if I leave it (Stop
) empty with no parameters, which uses the default, I get the exception, immediately. If I put in a timeout, it shuts down immediately without any problems.
@CheetahChrome Thanks, This solved the issue for me :-)
I'm running Win10, Microsoft.AspNet.SignalR.Client 2.4.0.0
Most helpful comment
I also get this error