Troubleshooting WebSocket Connection Issues in Azure App Service

Muhammad Umair 20 Reputation points
2024-05-31T11:11:41.1633333+00:00

Hello,

I am having trouble with my Azure App Service application that uses the socket.io library on the backend (Node.js) and the socket.io-client 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,

Umair

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

Accepted answer
  1. Vidya Viraktamath 160 Reputation points Microsoft Employee
    2024-05-31T12:53:41.8866667+00:00

    Hello,

    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 socket.io and socket.io-client 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

    Thanks.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.