Skip to content

WebSocket Connection Timeout with Gemini Live API #3035

@zhuqianyun-Rhine

Description

@zhuqianyun-Rhine

Bug Description

WebSocket connection to Gemini Live API randomly times out with ConnectionClosedError: no close frame received or sent, causing live agent sessions to terminate unexpectedly.

Environment

  • ADK Python Version: 1.15.1
  • Python Version: 3.13.3
  • Operating System: macOS (darwin 25.0.0)
  • Architecture: aarch64 (Apple Silicon)

Steps to Reproduce

  1. Start ADK web server with live WebSocket endpoint (/run_live)
  2. Establish WebSocket connection to Gemini Live API through ADK
  3. Maintain connection for extended period or during heavy usage
  4. Connection randomly times out and closes unexpectedly

Expected Behavior

WebSocket connection should remain stable and handle temporary network issues gracefully with proper reconnection mechanisms.

Actual Behavior

Connection abruptly terminates with error code 1011 (internal error) and the message "no close frame received or sent".

Error Log

2025-09-28 14:00:38,487 - ERROR - base_llm_flow.py:200 - Connection closed: no close frame received or sent.
2025-09-28 14:00:38,510 - ERROR - websocket_routes.py:199 - Error during live websocket communication: no close frame received or sent
Traceback (most recent call last):
  File "/Users/qianyunzhu/.local/share/uv/python/cpython-3.13.3-macos-aarch64-none/lib/python3.13/asyncio/selector_events.py", line 980, in _read_ready__get_buffer
    nbytes = self._sock.recv_into(buf)
TimeoutError: [Errno 60] Operation timed out

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/Users/qianyunzhu/Myproject/adk-python-ai-platform/src/seirobotics/ai/routers/conversation/websocket_routes.py", line 195, in agent_live_run
    task.result()
  ...
  File "/Users/qianyunzhu/Myproject/adk-python-ai-platform/.venv/lib/python3.13/site-packages/google/genai/live.py", line 521, in _receive
    raw_response = await self._ws.recv(decode=False)
  File "/Users/qianyunzhu/Myproject/adk-python-ai-platform/.venv/lib/python3.13/site-packages/websockets/asyncio/connection.py", line 322, in recv
    raise self.protocol.close_exc from self.recv_exc
websockets.exceptions.ConnectionClosedError: no close frame received or sent

Stack Trace Analysis

The error originates from:

  1. google.genai.live.py:521 - Low-level WebSocket receive operation
  2. gemini_llm_connection.py:149 - ADK's Gemini connection handler
  3. base_llm_flow.py:299 - LLM flow processing
  4. websocket_routes.py:127 - Application WebSocket routing

Potential Root Causes

  • Network timeout issues with Gemini Live API
  • Missing heartbeat/keepalive mechanism for long-lived connections
  • Insufficient timeout configuration for WebSocket connections
  • Possible API quota or rate limiting on Google's side

Impact

  • Live agent sessions terminate unexpectedly
  • Poor user experience due to connection instability
  • No automatic recovery mechanism available

Workaround

Currently implementing custom error handling and reconnection logic in application code, but this should be handled at the SDK level.

Additional Context

This issue occurs intermittently and seems to be more frequent during:

  • Extended conversation sessions
  • High API usage periods
  • Network instability

Suggested Solutions

  1. Implement automatic reconnection with exponential backoff
  2. Add configurable timeout parameters for WebSocket connections
  3. Implement heartbeat/ping mechanism to maintain connection health
  4. Better error classification and handling for different types of connection failures
  5. Add connection status monitoring and recovery mechanisms

Metadata

Metadata

Assignees

Labels

live[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