Troubleshooting WebSocket Connection Issues in Azure App Service

Muhammad Umair 20 Reputation points


I am having trouble with my Azure App Service application that uses the library on the backend (Node.js) and the library on the frontend (React). The frontend is hosted on an Azure Static Web App, while the backend is deployed on an App Service. I am receiving the error message "WebSocket is closed before the connection is established".

I am using the following App Service configuration:

  • App Service Plan: P2v3
  • Runtime Stack: Node - 16-lts
  • Region: West Europe

Is there a specific security setting within Azure that I need to adjust to ensure stable WebSocket connections? Also, does Linux App Service support WebSocket?

Thank you for any help you can provide.

Best regards,


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

Accepted answer
  1. Vidya Viraktamath 160 Reputation points Microsoft Employee


    Azure App Service supports WebSocket connections for both Windows and Linux. To ensure stable WebSocket connections, consider the following checks:

    WebSockets Enabled: Navigate to your App Service in the Azure portal, and under the 'Configuration' section, check the 'General settings' tab to ensure the 'Web sockets' option is enabled.

    Always On: In the same tab, make sure the 'Always On' setting is activated to keep your app loaded at all times, which is crucial for maintaining long-lived WebSocket connections.

    ARR Affinity: Disable 'ARR Affinity' in the 'General settings' tab if your application depends on a stateful connection to a particular instance, as this setting may route clients to the same instance, potentially disrupting WebSocket connections.

    Client and Server Versions: Verify that the versions of and are consistent across your frontend and backend to avoid compatibility issues.

    Upgrade Headers: Confirm that your application properly manages the HTTP Upgrade headers necessary for initiating a WebSocket connection.

    Kindly accept answer, if it helps


    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful