Share via

WebSocket Connection Fails on Azure Python Web App (No Response Headers)

Prasanna Sai Kommineni 40 Reputation points
2025-06-30T00:41:14.8733333+00:00

Hello Azure Support,

I am experiencing an issue with WebSocket connections on my Python-based Azure Web App (Linux App Service). Despite configuring the app correctly, the WebSocket connection fails during the handshake phase — the browser reports that the server is not sending response headers, and the connection status shows as "finished" in the Network tab.

Environment Details:

  • App Service OS: Linux
  • Runtime Stack: Python 3.x
  • Framework: FastAPI
  • **Startup Command:**gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app --timeout 240
  • WebSocket Route: /ws
  • Frontend Connection Code: const ws = new WebSocket("wss://" + location.host + "/ws");

Troubleshooting Steps Taken:

  • Verified that the WebSocket route is correctly defined in FastAPI.
  • Reduced Gunicorn workers to 1 to avoid concurrency issues.
  • Confirmed that the WebSocket URL and protocol (wss://) are correct.
  • Enabled logging and checked Log Stream — no clear errors, but no response headers are sent during the handshake.
  • Tested locally with Uvicorn — WebSocket works as expected.

Issue:

On Azure, the WebSocket connection fails silently. The server does not respond with headers, and the connection is closed immediately. This suggests the upgrade request is not reaching the app or is being blocked by the platform’s reverse proxy.

Request:

Could you please help investigate why the WebSocket upgrade request is not being handled properly on this Linux-based Python Web App? Is there any additional configuration or workaround required to support WebSockets in this environment?

Thank you for your assistance.

Hello Azure Support,

I am experiencing an issue with WebSocket connections on my Python-based Azure Web App (Linux App Service). Despite configuring the app correctly, the WebSocket connection fails during the handshake phase — the browser reports that the server is not sending response headers, and the connection status shows as "finished" in the Network tab.

Environment Details:

  • App Service OS: Linux
  • Runtime Stack: Python 3.x
  • Framework: FastAPI
  • Startup Command:
  • WebSocket Route: /ws
  • **Frontend Connection Code:**gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app --timeout 240
Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.


Answer accepted by question author

Bhargavi Naragani 7,940 Reputation points Moderator
2025-07-08T05:31:29.25+00:00

Hi Prasanna Sai Kommineni,

I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

Issue:

WebSocket Connection Fails on Azure Python Web App (No Response Headers)

Solution:

When we checked the config in az login console it shows websocketsEnabled as false, we ran the command to update the config Then websocket handshake was successful.

Please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Prasanna Sai Kommineni 40 Reputation points
    2025-07-07T19:20:07.34+00:00

    When we checked the config in az login console it shows websocketsEnabled as false ,We ran the command to update the config Then websocket handshake was successful .

    Was this answer helpful?

    0 comments No comments

Your answer

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