Hi, I am trying to use LiveKit on GCP (using react...
# ask-ai
s
Hi, I am trying to use LiveKit on GCP (using react-agent & python agent). While locally its working, when sendingthe join-room request on the cloud, agent is not being added to the room, and I get the following logs from the backend: 2025-10-20 154420.519 IDT 2025-10-20 124420,519 INFO src.agent: /join-room called with room=test, AGENT_NAME=danika-agent, lkapi_is_none=False 2025-10-20 154420.614 IDT INFO: 169.254.169.126:16980 - "POST /join-room HTTP/1.1" 200 OK 2025-10-20 154420.674 IDT 2025-10-20 124420,674 INFO livekit.agents: received job request 2025-10-20 155517.182 IDT 2025-10-20 125516,882 INFO livekit.agents: initializing process 2025-10-20 155531.183 IDT 2025-10-20 125531,183 INFO livekit.agents: initializing process 2025-10-20 155531.882 IDT 2025-10-20 125531,883 INFO livekit.agents: killing process 2025-10-20 155537.381 IDT 2025-10-20 125531,883 ERROR livekit.agents: error initializing process 2025-10-20 155537.381 IDT Traceback (most recent call last): File "/usr/local/lib/python3.11/asyncio/tasks.py", line 500, in wait_for return fut.result() ^^^^^^^^^^^^ File "/app/.venv/lib/python3.11/site-packages/livekit/agents/ipc/channel.py", line 47, in arecv_message return _read_message(await dplx.recv_bytes(), messages) ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/.venv/lib/python3.11/site-packages/livekit/agents/utils/aio/duplex_unix.py", line 35, in recv_bytes len_bytes = await self._reader.readexactly(4) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/streams.py", line 750, in readexactly await self._wait_for_data('readexactly') File "/usr/local/lib/python3.11/asyncio/streams.py", line 543, in _wait_for_data await self._waiter 2025-10-20 155537.381 IDT asyncio.exceptions.CancelledError 2025-10-20 155537.381 IDT The above exception was the direct cause of the following exception: 2025-10-20 155537.381 IDT Traceback (most recent call last): File "/app/.venv/lib/python3.11/site-packages/livekit/agents/ipc/proc_pool.py", line 167, in _proc_spawn_task await proc.initialize() File "/app/.venv/lib/python3.11/site-packages/livekit/agents/ipc/supervised_proc.py", line 169, in initialize init_res = await asyncio.wait_for( ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/tasks.py", line 502, in wait_for raise exceptions.TimeoutError() from exc 2025-10-20 155537.381 IDT TimeoutError can you help me solve this issue?
t
Thanks for reaching out, Bar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The issue you're experiencing with agents not joining the room and the TimeoutError during process initialization can be frustrating, but don’t worry—we’re here to work through it together. Let’s go through some steps that might help resolve this: 1. Adjust Initialization Timeout: Sometimes, increasing the timeout for process initialization in your Python agent's WorkerOptions can make a difference. You can try this:
Copy code
from livekit.agents import WorkerOptions

opts = WorkerOptions(
    initialize_process_timeout=30.0,  # Increase from default 10.0 seconds
)
2. Check GCP Firewall Rules: It’s important to ensure your GCP firewall settings allow the right traffic: • Outbound UDP traffic on all ports for WebRTC media • Inbound UDP traffic if agents need direct connections • Outbound TCP/443 connections for TURN server access 3. Force TURN for Restrictive Networks: If your network is a bit restrictive, you can try forcing clients to use TURN by setting:
Copy code
connectOpts.rtcConfig = { iceTransportPolicy: 'relay' }
4. Monitor Resources: Also, double-check that your GCP instance has enough CPU, memory, and network bandwidth to handle agent initialization smoothly. 5. Debugging Steps: • Look at the agent logs for any specific error messages during initialization • Test network connectivity to the LiveKit server • Make sure your API keys and tokens are set up correctly If any of these steps feel unclear or if you’d like some more personalized guidance with your GCP setup, please don’t hesitate to reach out. I’m here to help you get this sorted! Sources: livekit-agents/livekit/agents/worker.py | Firewall Tips | Connecting to LiveKit | LiveKit Docs | CreateRoom() is Taking Too Long
s
what about Use
job_executor_type="thread"?
will it help with this issue?
t
Using job_executor_type="thread" is a great way to help resolve the TimeoutError during process initialization. It works by cutting down the overhead that comes with creating new processes, which means your startup times get faster. Since threads are created more quickly than processes, this approach can really reduce the chance of running into that pesky initialization timeout. Here’s a simple way to set it up in your Python agent:
Copy code
from livekit.agents import WorkerOptions, JobExecutorType

opts = WorkerOptions(
    entrypoint_fnc=your_entrypoint,
    job_executor_type=JobExecutorType.THREAD,
    initialize_process_timeout=10.0  # Timeout still applies to thread initialization
)
Just a couple of things to keep in mind: • Reduced isolation: Since threads share the same process space, a crash in one job might impact others. • Resource contention: Threads will compete for the same process resources. If you want to give this a try or have any questions along the way, please don’t hesitate to reach out—I’m here to help! Sources: livekit-agents/livekit/agents/ipc/job_proc_executor.py | Job lifecycle | LiveKit Docs | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS