AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Async SSE Transport Shutdown Blocks Or Raises QueueFull When Bounded Event Queue Is Full

ProtocolSseTransport uses a blocking queue.put(None) in the pump's finally block to signal EOF. When the bounded queue is full and no consumer is draining, handle.close() raises asyncio.QueueFull and transport.close() blocks indefinitely, preventing clean shutdown and leaking resources.

highConfidence 93%Langgraph-SdkState ManagementStateGraphAffected V0.4.6

Origin Analysis

In ProtocolSseTransport._run_stream, the finally block always awaits queue.put(None) to enqueue the terminal sentinel. With max_queue_size=1 and a producer filling the queue while no consumer is active, this put blocks because the queue is full. handle.close() also attempts to enqueue a sentinel directly, raising QueueFull before cancelling the pump. The terminal state is tied to the public done future, which can be cancelled independently, leading to premature stream termination or hangs.
1. Install httpx and langgraph-sdk 0.4.6. 2. Save the provided reproducer as repro.py. 3. Run `python repro.py handle`: observe handle.close() raises asyncio.QueueFull. 4. Run `python repro.py transport`: observe transport.close() blocks because the cancelled pump awaits queue.put(None) in its finally block while the queue is full.

Fixing Code Block

Edge Case Audit

This hotfix assumes a single consumer per event stream; multiple concurrent consumers of the same queue are not supported and could lead to missed terminal events or hangs. If max_queue_size is 0 (unbounded), queue.full() always returns False, so the original blocking behavior remains but is safe. The patch has not been accepted upstream; before deploying, run the full SDK test suite, including the nine regression cases mentioned in the issue, especially under high concurrency. To roll back, revert this patch and avoid max_queue_size values less than 2 or ensure a consumer is always active; however, the original bug will persist.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state