1

I have an AngularJS application with a .NET Core back-end, using an Nginx server, and I'm using the following front-end SignalR library:

https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/3.1.3/signalr.min.js

The application works fine, however after about 30-40 mins, the following error appears in the console, and the client no longer displays any real-time messages. I need to refresh the browser for it to work again. This occurs on both Chrome and Firefox:

Error: Connection disconnected with error 'Error: WebSocket closed with status code: 1006 ()

enter image description here

I've looked at these questions, but they haven't solved my issue:

getting the reason why websockets closed with close code 1006

SignalR Core - Error: Websocket closed with status code: 1006

I've tried:

  • Setting the following configuration settings on Nginx

    proxy_read_timeout 86400s;

    proxy_send_timeout 86400s;

  • Installing a websockets service in Nginx (that seems to at least be giving me a websocket connection - and I've verified that it's using wss): enter image description here

  • Restarting the client hub after it closes:

    hub.deviceHub.onclose(async () => {
        console.log("restarting hub connection after it was closed");
        await hub.StartConnection;
    });
    

None of this fixes the issue. What could be causing this, and what else could I try?

I have a related question here about the SignalR connection completing failing at the back-end after about 2 weeks - this provides more detail about the way the back-end is set up:

Server-side SignalR connection fails after significant uptime

Nemanja Todorovic
  • 2,521
  • 2
  • 19
  • 30
Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
  • 1
    You can try to turn the `Microsoft.AspNetCore.SignalR` logging to `Trace` level and check if there is more information there. – Fei Han Jun 15 '20 at 08:26

1 Answers1

1

This turned out to be an issue in the back end. The back end SignalR connection would drop and restart around every 40mins or so. When restarting the connection, I was re-using the existing connection. Now, I create a completely new connection at the backend before reconnecting. See this answer from @Mark Feldman for the solution to my issue - https://stackoverflow.com/a/63277203/1549918.

Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206