During active inbound calls, if there is a transient network hiccup or an abrupt disconnection on the WebSocket media channel (used for streaming audio chunks to/from Azure Communication Services), the application encounters an unhandled exception. Instead of gracefully attempting a reconnection or tearing down the call cleanly, the entire container session/worker process crashes.
To Reproduce
Initiate an inbound call to the service.
Establish the audio stream and begin a conversation.
Simulate a sudden network drop or manually terminate the WebSocket connection from the client side while audio data is actively being written/read.
Observe the application logs and container state.
Expected Behavior
The application should catch the connection drop cleanly, stop trying to write to the closed socket, log a warning, and gracefully terminate the specific call session (or attempt a brief reconnection handshake) without crashing the entire service worker process.
Actual Behavior / Logs
The application throws an unhandled ConnectionClosedError or BrokenPipeError deep within the media streaming loop, causing the FastAPI/Python worker to panic and terminate.
Plaintext
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 254, in run_asgi
result = await app(self.scope, self.receive, self.send)
...
File "./app/media/streamer.py", line 84, in stream_audio
await websocket.send_bytes(chunk)
File "/usr/local/lib/python3.11/site-packages/starlette/websockets.py", line 133, in send_bytes
await self.send({"type": "websocket.send", "bytes": data})
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
CRITICAL:root:Worker process died due to unhandled WebSocket exception. Terminating container.
Environment Details
Language/Framework: Python 3.11 / FastAPI
Deployment: Azure Container Apps / Docker
Dependencies: websockets, azure-communication-callautomation
During active inbound calls, if there is a transient network hiccup or an abrupt disconnection on the WebSocket media channel (used for streaming audio chunks to/from Azure Communication Services), the application encounters an unhandled exception. Instead of gracefully attempting a reconnection or tearing down the call cleanly, the entire container session/worker process crashes.
To Reproduce
Initiate an inbound call to the service.
Establish the audio stream and begin a conversation.
Simulate a sudden network drop or manually terminate the WebSocket connection from the client side while audio data is actively being written/read.
Observe the application logs and container state.
Expected Behavior
The application should catch the connection drop cleanly, stop trying to write to the closed socket, log a warning, and gracefully terminate the specific call session (or attempt a brief reconnection handshake) without crashing the entire service worker process.
Actual Behavior / Logs
The application throws an unhandled ConnectionClosedError or BrokenPipeError deep within the media streaming loop, causing the FastAPI/Python worker to panic and terminate.
Plaintext
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 254, in run_asgi
result = await app(self.scope, self.receive, self.send)
...
File "./app/media/streamer.py", line 84, in stream_audio
await websocket.send_bytes(chunk)
File "/usr/local/lib/python3.11/site-packages/starlette/websockets.py", line 133, in send_bytes
await self.send({"type": "websocket.send", "bytes": data})
websockets.exceptions.ConnectionClosedError: code = 1006 (connection closed abnormally [internal]), no reason
CRITICAL:root:Worker process died due to unhandled WebSocket exception. Terminating container.
Environment Details
Language/Framework: Python 3.11 / FastAPI
Deployment: Azure Container Apps / Docker
Dependencies: websockets, azure-communication-callautomation