event loop blocked for 4355ms at \“/usr/local/lib/python3.14/ssl.py\”, line 1140, in read; synchronous work on the agent loop delays audio and turn handling, move it to a thread or an async client
Getting the above error, what should be the reason and what changes need to be made. Why suddenly getting this kind of error ? till yesterday it is working fine
Hi, I don’t think it’s in the docs, but the feature was introduced here: [Python, NodeJS]
I also did a little write up about it here: https://livekit.com/blog/diagnosing-blocked-event-loops#if-the-immediate-cause-isnt-obvious
LiveKit Agents watches its own event loop and reports every stall of 100ms or more
Something is blocking your event loop, and the error message is pointing you to the line (there should also be an OTEL event). Why this suddenly started happening, I can’t say - it’s coming from your agent.
@siddharthmot the file in that message is the useful clue. On Python 3.14, line 1140 of ssl.py is inside SSLSocket.read, a blocking TLS read. asyncio never does one of those itself; its own TLS goes through a different class. So something in your agent is calling a synchronous HTTPS client on the event loop and waiting about 4.3 seconds for the server to answer.
The usual culprits, inside a tool or a hook: requests, a sync httpx.Client, the sync OpenAI() client instead of AsyncOpenAI(), boto3, or a database driver connecting over TLS.
On why it started suddenly, two likely causes:
- The call was always blocking, but the server it talks to got slower. The 4355ms is mostly the remote’s response time.
- You picked up a newer livekit-agents. The blocked-loop report is fairly new, so if your requirements aren’t pinned to an exact version, a redeploy can switch on the warning with no change to your code. The blocking was there before; you just couldn’t see it.
To find the caller, look further up the stack for the first frame in your own code. The OTEL event Darryn mentioned carries it, or grep your agent for the clients above.
The fix is the async client (AsyncOpenAI, httpx.AsyncClient, aiohttp), or moving the call off the loop:
result = await asyncio.to_thread(sync_call, arg)
Give it a timeout either way. While the loop is blocked, the agent can’t hear the caller, so 4 seconds is a long time on a call.