I have self-hosted the livekit in a vm, and trying...
# ask-ai
f
I have self-hosted the livekit in a vm, and trying to add agents and users in a room but sometimes agent is not joining the room. Because of this issue I created a new instance for the livekit and got it hosted at same place but with more resources and in the starting it worked really well. But after sometime, it stopped working consistently. The agent not joining. But the code is working fine with the livekit cloud, i.e., cloud credentials. Can you help me with this ?
t
Thanks for reaching out, JayaKrishna. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you get to the bottom of the issue with agents not joining rooms in your self-hosted LiveKit instance. When you have a moment, could you please share a few details with me? • Are the
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
all set up correctly in your self-hosted environment? • Have you had a chance to look at the logs for both the agent and the LiveKit server? If yes, did you notice any errors or warnings? • Which versions of the LiveKit server and SDK are you currently using? • Are there any particular network settings, like firewalls or NAT, that might be impacting connectivity? • Does this problem happen all the time, or only in certain situations, like when there’s a high load? With these details, I’ll be better equipped to understand what’s going on and guide you toward the best solution. Looking forward to your response! Sources: Deploying to custom environments | LiveKit Docs | LiveKit Docs | LiveKit Cloud | LiveKit Docs | Still Have Questions | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik...
f
• Yes
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
all setup correctly in self-hosted environment. Because initially it worked really well. • I don't see any issues in the logs. • No firewalls yet • Sometimes it's working, sometimes it is not working.
t
I'm sorry to hear you're experiencing intermittent issues with agents not joining rooms in your self-hosted LiveKit instance. Let's work through this together! There are a few common causes, and some steps we can take to help pinpoint and resolve the problem: • Enable Debug Logging: Try running your agents with debug flags enabled. This will capture detailed logs around worker registration, job assignment, and room join attempts, which can reveal any silent failures. • Use the Agent Load Tester: The
livekit-cli
tool has a load testing feature that simulates room creation and agent dispatch. It provides useful metrics like join delays and success rates, which can help reproduce and better understand the issue. • Monitor Worker Behavior: Keep an eye on your workers’ WebSocket connections and heartbeats. Sometimes high CPU usage or network hiccups can cause temporary unavailability, leading to missed dispatch requests. • Check Job Assignment Timeouts: Remember that workers have a 7.5-second timeout to accept jobs, and room connections should be established within 10 seconds. Delays here might cause failures without clear error messages. • Implement Monitoring: Setting up Prometheus metrics or health check endpoints can be really helpful to track worker load, job counts, and connection status over time. This way, you can spot if high load is affecting dispatch reliability. To help us narrow things down a bit more: • Are agents struggling to join specific rooms, or is it happening across all rooms? • Do you notice if the issue happens during peak load times or particular periods? • Have you had a chance to test with the load tester to see join success rates and latency? These steps should give us a clearer picture and guide us toward a solution that improves reliability. Please feel free to reach out if you’d like any help setting these up or have more questions—I’m here to support you! Sources: pkg/loadtester/agentloadtester.go | livekit-plugins/livekit-plugins-bithuman/livekit/plugins/bithuman/avatar.py | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | Community & Support | livekit/livekit_composite | DeepWiki | client/web/.github/ISSUE_TEMPLATE/bug_report.yaml
f
It's working fine in livekit cloud. When I setup my instance at first, it worked all the times. After that, it stopped working all the times. So based on this, Is my agent code is not handling everything correctly. Is my agent code opening something and not closing. Due to that we got this issue ? I have checked the cpu and memory load also. It is not using much hardly 1% to 2%.
t
I understand how frustrating this issue can be, and I’m here to help you work through it. It’s quite possible that unclosed resources in your agent code might be contributing to the problem. Managing resources carefully is really important for keeping your agent stable. If things like WebSocket connections, HTTP sessions, or process pools aren’t closed properly, it can slowly affect performance over time. Here are a few steps you might find helpful: • Make sure your agent code explicitly closes all resources when shutting down, including WebSocket connections, HTTP sessions, and any other system resources. • Take a close look for any memory leaks or unclosed resources, especially in parts of your code that handle errors or run for a long time. • Keep an eye on memory usage, CPU utilization, and error rates to spot any signs that resources might be running low. • Consider deploying multiple agents per
agent_name
to keep things running smoothly even if one job encounters a problem. Since you mentioned this doesn’t happen with LiveKit Cloud, it’s likely something specific to your self-hosted setup or custom agent implementation. If you’d like, I’m more than happy to guide you through the process of cleaning up resources or debugging your agent code further. Just let me know! Sources: README.md | agents/CHANGELOG.md | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | Deploying to custom environments | LiveKit Docs | Community & Support | livekit/livekit_composite | DeepWiki