Websocket connection to Azure Web App is closing with generic error 1006

Brian McAuley 5 Reputation points
2024-09-09T14:13:53.1866667+00:00

I have a rather complicated problem and need some advice from people who are familiar with how Azure App Service Web Apps work.

I am using SignalR (through a package called dotnetify) to hook up a ReactJs front end to a .NET Core 6 API. The production version of the API is hosted as an Azure App Service.

While running locally, I have never once seen any issue. When the application runs hosted on an App Service Plan, I intermittently get the following error:

Error: WebSocket closed with status code: 1006 ().

at push.18545.t.close (WebSocketTransport.ts:166:30)

at push.18545.t.connect.s.onclose (WebSocketTransport.ts:116:26)

I have multiple view models in my application, and only one view model ever encounters this. The others work consistently fine. This particular view model has to query for a lot of data and can take upwards of 5 to 30 seconds to load (depending on physical distance from the service which is hosted in US West).

What's interesting is, when I run locally, I can put a Thread.Sleep for 60 seconds in to the view model and still never see a timeout, so my intuition tells me there is something related to the hosting environment that is forcibly closing the connection. I have WebSockets, AlwaysOn, and AARAffinity all enabled. Is there some underlying timeout mechanism on the web app that I am unaware of? I am not using a load balancer or application gateway. There are times based on traffic load where I will scale out to up to 3 instances. This error happens regularly even on only 1 instance.

Any guidance is hugely appreciated.

Thanks,

Brian McAuley

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,902 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 16,586 Reputation points Microsoft Employee
    2024-09-30T00:41:52.3733333+00:00

    @Brian McAuley The WebSocket error 1006 typically indicates that the connection was closed abnormally, without a proper closing handshake. Here are a few things you might want to consider:

    1. Idle Timeout: Azure App Service has an idle timeout setting that might be closing your WebSocket connections prematurely. You can increase the idle timeout by setting the WEBSITES_CONTAINER_IDLE_TIMEOUT app setting to a higher value. The default is 20 minutes, but you can increase it up to 30 minutes (1800 seconds).
    2. WebSocket Configuration: Ensure that WebSockets are properly enabled in your Azure App Service configuration. Sometimes, issues can arise if WebSockets are not correctly set up in the IIS features or if there are firewall rules blocking WebSocket traffic.

    Network Latency and Load: Since the issue occurs more frequently under load or when scaling out, it might be related to network latency or resource contention. Monitoring your app’s performance and scaling settings might provide insights. Tools like Azure Application Insights can help you track these metrics.

    SignalR Configuration: Check your SignalR configuration settings. Sometimes tweaking the transport settings or increasing the keep-alive interval can help maintain the connection.

    Instance-Specific Issues: Since the problem occurs even with a single instance, it might be worth investigating if there’s something specific to that instance or its configuration. Restarting the instance or redeploying the app might help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.