raise Exception("worker connection closed unexpect...
# ask-ai
m
raise Exception("worker connection closed unexpectedly") llm_engine-1 | Exception: worker connection closed unexpectedly llm_engine-1 | {"message": "failed to connect to livekit, retrying in 0s", "level": "WARNING", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.10/site-packages/livekit/agents/worker.py\", line 651, in _connection_task\n await self._run_ws(ws)\n File \"/usr/local/lib/python3.10/site-packages/livekit/agents/worker.py\", line 732, in _run_ws\n await asyncio.gather(*tasks)\n File \"/usr/local/lib/python3.10/site-packages/livekit/agents/worker.py\", line 704, in _recv_task\n raise Exception(\"worker connection closed unexpectedly\")\nException: worker connection closed unexpectedly", "timestamp": "2026-02-14T132638.187261+00:00"} llm_engine-1 | INFOlivekit.agentsregistered worker llm_engine-1 | {"message": "registered worker", "level": "INFO", "name": "livekit.agents", "id": "AW_AeGH5GcrnzM4", "url": "wss://dpi-kccd98ec.livekit.cloud", "region": "Saudi Arabia", "protocol": 16, "timestamp": "2026-02-14T132639.419455+00:00"}
t
Thanks for reaching out, Anigilaje. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I see you're hitting a recurring error:
Exception: worker connection closed unexpectedly
from the LiveKit agent worker. You also have a log line showing the worker registered successfully (wss://dpi-kccd98ec.livekit.cloud) right before the connection closed. I’ll help you diagnose likely causes and walk through targeted checks and mitigations. Quick summary of likely causes • Network instability causing the WebSocket/WebRTC connection to drop. • A firewall, VPN, or security proxy (for example, ZScaler or another DPI proxy) interfering with WebSocket, TURN, or encrypted media streams. • Intermediate proxies performing Deep Packet Inspection that break WebRTC/TURN traffic. Actionable checks and next steps 1. Run the Connection Test utility ◦ Use the LiveKit Connection Test to verify WebSocket, WebRTC, and TURN connectivity from the agent’s host. If tests fail for WebSocket or TURN, the problem is almost certainly network/proxy related. 1. Check for proxies/ DPI (ZScaler-like) ◦ If your network uses ZScaler or a DPI proxy, configure bypass rules for your LiveKit project domain and TURN servers. Example bypass entries: ▪︎ turn.livekit.cloud — detect_protocol(no) ▪︎ dpi-kccd98ec.livekit.cloud — detect_protocol(no) ◦ Bypassing protocol detection prevents the proxy from attempting to inspect or modify encrypted WebRTC/TURN traffic (which breaks connections). 1. Verify ports and protocols ◦ Ensure outbound ports and protocols required by WebSocket, WebRTC, and TURN are allowed from the agent host (including UDP for TURN if you use UDP). ◦ Temporarily disable VPNs or test from a network without corporate proxies to confirm if the proxy is the cause. 1. Inspect agent logs & retry behavior ◦ Confirm the agent’s retry/backoff is enabled. The agent log shows “failed to connect to livekit, retrying in 0s” which means it does attempt reconnects — keep an eye on repeated failures and timestamps to see if disconnections are transient or immediate after registration. 1. Reproduce from a different network/location ◦ Try running the worker from a different network (home network, cloud VM in a different region) to determine whether the issue is local-network specific. What I can help with next • If you can share the outcome of the Connection Test or the specific network environment (behind ZScaler or other proxy?), I’ll suggest the exact bypass rules and further steps. • If you prefer, paste a sanitized portion of more detailed agent logs (timestamps around registration and the failure) and I’ll help pinpoint whether the disconnect is immediately post-registration or after some activity. If you don’t use a proxy or the Connection Test passes, tell me the test results and I’ll guide you through additional logs and configuration checks. Sources: Configure ZScaler proxy for LiveKit connections | LiveKit | Diagnosing Connection Errors with the Connection Test Utility | LiveKit | server-sdk-go | livekit/livekit_composite | DeepWiki
m
i am runnig the agent in nigeria
t
Thanks — that’s helpful. Since you’re running the agent in Nigeria, let’s narrow this down so we can find the root cause of the “worker connection closed unexpectedly” disconnect. A few targeted questions • Is the agent host on a corporate network, cloud VM, home network, or mobile data? • Is there a corporate proxy, VPN, or security service in the path (examples: ZScaler, Palo Alto, other DPI/forward proxy)? • Can you run the LiveKit Connection Test from the same host and share the results (WebSocket, WebRTC, TURN checks)? If you can’t run it, tell me whether WebSocket to wss://dpi-kccd98ec.livekit.cloud succeeds from that host (you can test with a simple WebSocket client). Immediate checks you can run now 1. Try from an alternate network ◦ Run the agent from a different network (home, different cloud region, or mobile tether). If it works there, the issue is network/proxy related in your original location. 1. Test WebSocket connectivity ◦ From the agent host run a basic WebSocket test to wss://dpi-kccd98ec.livekit.cloud. If the handshake fails or drops quickly, that points to a proxy or firewall closing connections. 1. Check for proxies/DPI ◦ If a proxy or DPI (e.g., ZScaler) is present, configure bypass rules for: ▪︎
turn.livekit.cloud
(detect_protocol=no) ▪︎
dpi-kccd98ec.livekit.cloud
(detect_protocol=no) ◦ These bypass rules prevent protocol inspection that breaks WebRTC/TURN encrypted streams. 1. Confirm outbound ports/protocols ◦ Ensure outbound TCP for WebSocket and TCP/UDP for TURN are allowed. TURN over UDP is preferred; if UDP is blocked, TURN TCP must be allowed. 1. Review agent logs around disconnects ◦ Share a short, sanitized snippet of logs from just before registration through the disconnect (timestamps). I’ll look for patterns (immediate close vs. after activity). If tests fail or you have a proxy • Share the Connection Test results or confirm proxy type and I’ll provide exact bypass entries and any network settings to change. Next step suggestion • If you can, run the Connection Test from that Nigerian host and paste the results (or paste the small log snippet and answer the proxy/network questions). I’ll use that to give precise steps you can apply.