aspnet / AzureSignalR-samples

Code samples for Azure SignalR
MIT License
327 stars 390 forks source link

Connection to WebSocket disconnects no matter the timeout increases. (Azure SignalR) #246

Open charlesoto opened 11 months ago

charlesoto commented 11 months ago

For both ASP.NET and ASP.NET Core SignalR, when connecting to an Azure SignalR service. If by any reason, the user loses connection to internet, and then sends a message while being offline, the Websocket will close returning a 1006 Close code. By the time the internet comes back (Approximately 7-15 seconds), the message is lost, and the user needs to re click the action in order to send the message again after the hub is reconnected.

I have tried to increate all time outs mentioned here:

https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events

and

https://learn.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-8.0&tabs=dotnet

How to replicate this issue:

  1. Clone and run any of the samples in this source code (I ran ChatRoom)
  2. Entered the chat and send a first message
  3. Then disconnect the internet (Turn off wifi, disconnect cable, etc) and rapidly send another message.
  4. Wait at least 10 seconds
  5. Turn internet back on
  6. Websocket Close with error: image image
charlesoto commented 11 months ago

Yes,

We do not want our signalR to be disconnecting that often because some of our clients have slower internet connection which is the reason why we raised the timeouts of the Hub.

We raised Keep Alive to 50 seconds and the connection time out to 150 seconds. Yet, our hub gets disconnected in just 10-15 seconds when their internet fail, sometimes causing them to trigger the action over and over because it is not responsive with the hub server.

I could replicate the issue by reproducing the steps I mentioned.

  1. Clone and run any of the samples in this source code (I ran ChatRoom)
  2. Entered the chat and send a first message
  3. Then disconnect the internet (Turn off wifi, disconnect cable, etc) and rapidly send another message.
  4. Wait at least 10 seconds (It is supposed to stay connected waiting for the message back from the server due to the longer timeout setting)
  5. Turn internet back on
  6. Websocket Close with error.

Why does it keep disconnecting so fast instead of listening to the timeouts we set up? This happens in both ASP.NET Core and ASP.NET Framework.

On Thu, Nov 16, 2023 at 10:05 PM Liangying.Wei @.***> wrote:

Could you share more about your expected behavior?

IMHO, the behavior described works as expected:

  1. When a message is sent when offline, WebSocket is closed, which means the underlying transport for signalr connection is closed, so signalr connection is closed. The messages sent to this connection is lost.
  2. When internet comes back, since the signalr connection is closed, it needs to reconnect.

— Reply to this email directly, view it on GitHub https://github.com/aspnet/AzureSignalR-samples/issues/246#issuecomment-1815676770, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASWDVRQLHM3CCI63YDPKYJDYE3H6JAVCNFSM6AAAAAA7O6GHKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJVGY3TMNZXGA . You are receiving this because you authored the thread.Message ID: @.***>

charlesoto commented 11 months ago

The interesting thing however is that if the internet connection is lost for less than 10 seconds, it waits for the messages to come back from the server properly without any issues.

On Thu, Nov 16, 2023 at 10:35 PM Charles Soto @.***> wrote:

Yes,

We do not want our signalR to be disconnecting that often because some of our clients have slower internet connection which is the reason why we raised the timeouts of the Hub.

We raised Keep Alive to 50 seconds and the connection time out to 150 seconds. Yet, our hub gets disconnected in just 10-15 seconds when their internet fail, sometimes causing them to trigger the action over and over because it is not responsive with the hub server.

I could replicate the issue by reproducing the steps I mentioned.

  1. Clone and run any of the samples in this source code (I ran ChatRoom)
  2. Entered the chat and send a first message
  3. Then disconnect the internet (Turn off wifi, disconnect cable, etc) and rapidly send another message.
  4. Wait at least 10 seconds (It is supposed to stay connected waiting for the message back from the server due to the longer timeout setting)
  5. Turn internet back on
  6. Websocket Close with error.

Why does it keep disconnecting so fast instead of listening to the timeouts we set up? This happens in both ASP.NET Core and ASP.NET Framework.

On Thu, Nov 16, 2023 at 10:05 PM Liangying.Wei @.***> wrote:

Could you share more about your expected behavior?

IMHO, the behavior described works as expected:

  1. When a message is sent when offline, WebSocket is closed, which means the underlying transport for signalr connection is closed, so signalr connection is closed. The messages sent to this connection is lost.
  2. When internet comes back, since the signalr connection is closed, it needs to reconnect.

— Reply to this email directly, view it on GitHub https://github.com/aspnet/AzureSignalR-samples/issues/246#issuecomment-1815676770, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASWDVRQLHM3CCI63YDPKYJDYE3H6JAVCNFSM6AAAAAA7O6GHKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJVGY3TMNZXGA . You are receiving this because you authored the thread.Message ID: @.***>