Skip to content

[Bug] _async_gen_to_sync_gen deadlocks container when SSE consumer disconnects (queue blocks worker loop thread) #482

Description

@kedazhu1-ai

In _async_gen_to_sync_gen:

q: queue.Queue = queue.Queue(maxsize=100)

async def _produce() -> None:
async for chunk in async_gen:
q.put((True, chunk)) # ← BLOCKING put, no timeout
q.put((True, _DONE))

Sync consumer

while True:
ok, value = q.get() # ← stops iterating when SSE disconnects
yield value

Here's the deadlock chain:
SSE client disconnects → Starlette stops iterating the sync generator
_produce() is still running on the worker loop thread, producing chunks
Queue fills up to 100 items → q.put() blocks the worker loop thread
Worker loop thread is now frozen → container can't process ANY new requests
Container stays deadlocked until idle timeout

This is not something you can work around on your side — q.put() is a blocking call with no timeout or cancellation mechanism. The fix needs to be in the SDK.

Code ref: app.py L737-L750

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions