dotnet / dotnet/aspnetcore

SignalR client hanging on reconnections

Open
#63,333 2 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Using Microsoft.AspNetCore.SignalR.Client v9.0.8 we are seeing issues during the reconnection process. If the SignalR connection is lost automatic reconnection is successful most of the time. But occasional it will fail to reconnect and the Hub Connection seems to hang.

Other parts of the application continue as normal and only a restart of the application resolves the issue.

This is running on Debian GNU/Linux 12 (bookworm)
Version: 6.1.0-38-cloud-amd64

From the diagnostic file HubConnection log
```
07:00:14.4452|DEBUG|Processing 164 byte message from server.
07:00:15.8458|ERROR|The server connection was terminated with an error. System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
at System.Net.WebSockets.ManagedWebSocket.ThrowEOFUnexpected()
at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartReceiving(WebSocket socket)
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at Microsoft.AspNetCore.SignalR.Client.HubConnection.ReceiveLoop(ConnectionState connectionState)
07:00:15.8458|DEBUG|Canceling all outstanding invocations.
07:00:15.8458|ERROR|Connection is shutting down due to an error. System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
at System.Net.WebSockets.ManagedWebSocket.ThrowEOFUnexpected()
at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartReceiving(WebSocket socket)
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at Microsoft.AspNetCore.SignalR.Client.HubConnection.ReceiveLoop(ConnectionState connectionState)
07:00:15.8458|DEBUG|Invoking the Closed event handler.
07:00:25.8554|DEBUG|Starting HubConnection.
.... No more events from here
```

From the HttpConnection log

```
06:59:13.9827|DEBUG|Disposing HttpConnection.
06:59:13.9853|INFO|HttpConnection Disposed.
06:59:24.0214|DEBUG|Starting HttpConnection.
06:59:24.0245|DEBUG|Starting transport 'WebSockets' with Url: https://...
06:59:24.2330|DEBUG|Transport 'WebSockets' started.
06:59:24.2330|INFO|HttpConnection Started.
07:00:15.8458|DEBUG|Disposing HttpConnection.
07:00:15.8458|INFO|HttpConnection Disposed.
07:00:25.8554|DEBUG|Starting HttpConnection.
07:00:25.8554|DEBUG|Starting transport 'WebSockets' with Url: https://....
... No more events from here
```

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.