Skip to content

When running a live session with the ADK, a websockets.exceptions.ConnectionClosedError occurs with error code 1011 (internal error). #3692

@mohamed-em2m

Description

@mohamed-em2m

Describe the bug When running a live session with the ADK, a websockets.exceptions.ConnectionClosedError occurs with error code 1011 (internal error). The error message indicates that a thread was cancelled while writing a status, leading to a premature closing of the streaming connection.
Logs:

Start the application which utilizes google-adk for live interactions.
Initiate a live chat/voice session which calls the runner.run_live(...) method.
During the streaming communication with the backend, the connection is unexpectedly terminated.
The following error and stack trace are observed:
ERROR:google_adk.google.adk.flows.llm_flows.base_llm_flow:Connection closed: received 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED: ; then sent 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED: .
[2025-11-24 18:36:20] error: ADK receive failed: received 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED: ; then sent 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED:
Traceback (most recent call last):
File "/home/emam/deeb_realities_projects/HIM/src/api/routers/chat.py", line 921, in run_adk_live
async for event in runner.run_live(
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/runners.py", line 856, in run_live
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/runners.py", line 653, in _exec_with_plugin
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/runners.py", line 845, in execute
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/agents/base_agent.py", line 327, in run_live
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/agents/llm_agent.py", line 462, in _run_live_impl
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 153, in run_live
async for event in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 300, in _receive_from_model
async for llm_response in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/adk/models/gemini_llm_connection.py", line 149, in receive
async for message in agen:
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/genai/live.py", line 448, in receive
while result := await self._receive():
^^^^^^^^^^^^^^^^^^^^^
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/google/genai/live.py", line 529, in _receive
raw_response = await self._ws.recv(decode=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/emam/.pyenv/versions/3.12.7/lib/python3.12/site-packages/websockets/asyncio/connection.py", line 322, in recv
raise self.protocol.close_exc from self.recv_exc
websockets.exceptions.ConnectionClosedError: received 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED: ; then sent 1011 (internal error) Thread was cancelled when writing StartStep status to channel.; Failed to close the streaming context; status = CANCELLED:
Expected behavior The live streaming connection should remain stable throughout the interaction, without being abruptly closed by an internal error. The run_live session should complete successfully or be terminated gracefully by the client or server, not by a thread cancellation error.

OS: Linux,fedora
Python version(python -V): Python 3.12.7
ADK version(pip show google-adk): 1.18.0
Model Information:

Are you using LiteLLM: No
Which model is being used(e.g. gemini-1.5-pro): gemini-2.5-flash-native-audio-preview-09-2025
Additional context The error seems to stem from the underlying google-generativeai and websockets libraries that the ADK uses for live/streaming functionality. The specific error message "Thread was cancelled when writing StartStep status to channel" suggests a potential race condition or an issue with how asynchronous tasks are being managed within the ADK or its dependencies during a live session

Metadata

Metadata

Labels

answered[Status] This issue has been answered by the maintainerlive[Component] This issue is related to live, voice and video chat

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions