Getting this error: message: ConnectionError: coul...
# ask-ai
g
Getting this error: message: ConnectionError: could not establish pc connection When connecting to the livekit server for token. I can share the JS code if you want to check
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m looking into the "ConnectionError: could not establish pc connection" you're seeing when requesting a token. Can you please share: • The JS snippet where you call
room.connect()
(including any
rtcConfig
options you pass) • Browser and OS, and whether you're on a corporate network, VPN, or home network • Whether your LiveKit instance is cloud-hosted or self-hosted • Any console logs around the error and whether signaling (WebSocket) connected successfully In the meantime you can run these quick checks and share results: • Force TURN-only to see if relay works:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
• Run the connection checker:
Copy code
import { ConnectionCheck } from '@livekit/client-sdk';
const checker = new ConnectionCheck({ url: wsUrl, token });
console.log(await checker.checkWebsocket());
console.log(await checker.checkWebRTC());
console.log(await checker.checkTURN());
Send the code and outputs and I’ll dive into the root cause. Sources: Connecting to LiveKit | LiveKit docs | Configuring firewalls | LiveKit docs | Firewall Tips | Diagnosing Connection Errors with Connection Test Utility | Deploy to a VM | LiveKit docs
g
import { auth } from '@goodfit/auth/auth'; import { RoomAgentDispatch, RoomConfiguration } from '@alert-easter-19258/protocol'; import { AccessToken, type AccessTokenOptions, type VideoGrant, } from 'livekit-server-sdk'; import { nanoid } from 'nanoid'; import { headers } from 'next/headers'; import { type NextRequest, NextResponse } from 'next/server'; const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY; const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET; const LIVEKIT_URL = process.env.LIVEKIT_URL; export const revalidate = 0; // don't cache the results export type ConnectionMetadata = { serverUrl: string; roomName: string; participantName: string; participantToken: string; }; const PERMITTED_LANGUAGES = [ 'bn-IN', // bengali 'en-IN', // english (india) 'gu-IN', // gujarati 'hi-IN', // hindi 'kn-IN', // kannada 'ml-IN', // malayalam 'mr-IN', // marathi 'od-IN', // odia 'pa-IN', // punjabi 'ta-IN', // tamil 'te-IN', // telugu ]; export async function POST(_request_: NextRequest): Promise<Response> { try { if (!LIVEKIT_URL || !LIVEKIT_API_KEY || !LIVEKIT_API_SECRET) { return new NextResponse( '[ERROR]:(connection): livekit credentials not configured', { status: 500 }, ); } const body = await request.json(); const { prompt, greeting, slug, language, gender } = body; // session validation const session = await auth.api.getSession({ headers: await headers(), }); if (!session?.user) return new NextResponse('[ERROR]:(connection): unauthorized', { status: 401, }); const user = session.user; const activeRoomIdentifier = nanoid(); const token = await createParticipantToken( { identity: user.id, name: user.name }, activeRoomIdentifier, prompt, greeting, slug, gender, PERMITTED_LANGUAGES.includes(language) ? language : 'en-IN', ); // return connection details const data: ConnectionMetadata = { serverUrl: LIVEKIT_URL, roomName: activeRoomIdentifier, participantToken: token, participantName: user.name, }; return NextResponse.json(data, { headers: new Headers({ 'Cache-Control': 'no-store', }), }); } catch (error) { if (error instanceof Error) { console.error('[ERROR]:(connection/route):', error); return new NextResponse(error.message, { status: 500 }); } console.error('[ERROR]:(connection/route):', error); return new NextResponse('UNEXPECTED ERROR', { status: 500 }); } } function createParticipantToken( _userInfo_: AccessTokenOptions, _room_: string, _prompt_: string, _greeting_: string, _slug_: string, _gender_: string, _language_: string, ) { const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, { ...userInfo, ttl: '15m', }); const grant: VideoGrant = { room, roomJoin: true, canPublish: true, canPublishData: true, canSubscribe: true, }; at.addGrant(grant); at.roomConfig = new RoomConfiguration({ agents: [ new RoomAgentDispatch({ metadata: JSON.stringify({ gender, language, job_prompt: prompt, job_greeting: greeting, interview_slug: slug, }), }), ], }); return at.toJwt(); }
t
Thanks — I’m looking at the token-generation code you shared. A few quick observations and targeted next steps to narrow the "could not establish pc connection" issue. What I checked in your server code • Token creation looks correct: AccessToken is built with key/secret, VideoGrant added, `roomJoin`/publish/subcribe flags set, and
roomConfig
agents/metadata added before
toJwt()
. • TTL 15m is fine; returned response includes serverUrl, roomName, and participantToken as expected. What I need from you (please share) • The client-side JS where you call
room.connect(wsUrl, token)
(include any
rtcConfig
options). • Browser + OS + network type (home, corporate, mobile carrier, VPN). • Whether LIVEKIT_URL is a cloud URL (e.g., wss://{instance}.livekit.cloud) or your self-hosted domain. • Any console logs around connection (signaling/ICE/DTLS) and the exact stack trace for the ConnectionError. Immediate checks to run now 1) Verify signaling connects: • Confirm the client successfully opens WebSocket to
wsUrl
(no auth or CORS error). If signaling fails, the PC won't start. 2) Force TURN-only to test relay:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
If this succeeds, the issue is UDP/ICE on the network. 3) Run connection checks:
Copy code
import { ConnectionCheck } from '@livekit/client-sdk';
const checker = new ConnectionCheck({ url: wsUrl, token });
console.log(await checker.checkWebsocket());
console.log(await checker.checkWebRTC());
console.log(await checker.checkTURN());
Share outputs. 4) Network rules to confirm (especially on corporate/NAT): • Allow TCP 443 to *.livekit.cloud (signaling) and *.turn.livekit.cloud (TURN). • Allow UDP 50000–60000 for direct media if you want ICE/UDP. Other quick items to confirm • If self-hosted: TLS certs and DNS are valid for the LIVEKIT_URL and any TURN domain. • Client and server clocks are roughly synced (large clock skew can affect auth). Send the client connect code and the ConnectionCheck outputs and I’ll pinpoint next steps.
g
npm i @livekit/client-sdk this dfoes not work?
t
You're right —
npm i @livekit/client-sdk
does not work. Install the correct package:
Copy code
npm install livekit-client
# or
yarn add livekit-client
Then import and use it, for example:
Copy code
import { Room } from 'livekit-client';
const room = new Room();
await room.connect('wss://your-server.livekit.cloud', token);
If you want, paste your client-side connect code (how you call
room.connect()
), browser/OS, and whether you're on a corporate/VPN network — I’ll review next steps for the "could not establish pc connection" error. Sources: Connecting to LiveKit | LiveKit docs | JavaScript quickstart (web) | LiveKit docs | React quickstart | LiveKit docs | client-sdk-js | livekit/livekit_composite | DeepWiki
g
how do i use this: ConnectionCheck?
t
You're asking how to use ConnectionCheck — here's a concise step-by-step you can run in the browser client to diagnose the "could not establish pc connection" error. 1) Install and import
Copy code
npm install livekit-client
Copy code
import { ConnectionCheck } from 'livekit-client';
2) Create the checker
Copy code
const checker = new ConnectionCheck({
  url: wsUrl,    // the same wss://... URL you use for room.connect()
  token: token,  // token from your server
});
3) Run the basic checks (recommended)
Copy code
console.log(await checker.checkWebsocket()); // signaling
console.log(await checker.checkWebRTC());    // peer connection ability
console.log(await checker.checkTURN());     // TURN relay reachability
4) Optional checks
Copy code
console.log(await checker.checkReconnect());
console.log(await checker.checkPublishAudio());
console.log(await checker.checkPublishVideo());
5) Interpret results • Each result has `status`:
'PASSED' | 'FAILED' | 'SKIPPED'
. • If WebSocket fails → signaling/URL/token issue. • If WebRTC fails but TURN passes → UDP/ICE is blocked; use TURN. • If TURN fails → network or blocked access to TURN domains (check TCP:443 to *.turn.livekit.cloud). 6) Quick troubleshooting actions based on results • If TURN helps, connect with
rtcConfig: { iceTransportPolicy: 'relay' }
to force relay. • Confirm
wsUrl
uses
wss://
and token is valid. • Run checks from the same network (browser) that's failing. If you run those and paste the three outputs (
checkWebsocket
,
checkWebRTC
,
checkTURN
), I’ll interpret them and give next steps. Sources: Diagnosing Connection Errors with Connection Test Utility
g
{ logs: [ { level: 'error', message: 'this.url.startsWith is not a function' } ], name: 'WebSocketCheck', status: 4, description: 'Connecting to signal connection via WebSocket' } { logs: [ { level: 'warning', message: 'ports need to be open on firewall in order to connect.' }, { level: 'error', message: 'navigator is not defined' } ], name: 'WebRTCCheck', status: 4, description: 'Establishing WebRTC connection' } { logs: [ { level: 'error', message: 'navigator is not defined' } ], name: 'TURNCheck', status: 4, description: 'Can connect via TURN' }
t
Thanks — the logs show the root cause. What the logs tell us •
this.url.startsWith is not a function
(WebSocketCheck): your
url
argument is not a string (likely an object). •
navigator is not defined
(WebRTCCheck & TURNCheck): you're running ConnectionCheck in a non-browser environment (Node/SSR). ConnectionCheck requires browser WebRTC APIs like
navigator
and
RTCPeerConnection
. What to do next 1. Run ConnectionCheck in the browser (not server/Next.js server code). Example:
Copy code
import { ConnectionCheck } from 'livekit-client';

const checker = new ConnectionCheck({ url: 'wss://your-server.livekit.cloud', token });
console.log(await checker.checkWebsocket());
console.log(await checker.checkWebRTC());
console.log(await checker.checkTURN());
1. Fix the
url
value so it's a string (e.g.,
wsUrl
should be
'wss://...'
, not an object). 2. If you can’t run tests in the browser, use the LiveKit Connection Tester: https://livekit.io/connection-test If you run the three checks from a browser and paste the outputs here, I’ll interpret them and give targeted next steps. If you want, paste your client-side
room.connect(wsUrl, token)
call and I’ll check the
wsUrl
format and options. Sources: Diagnosing Connection Errors with Connection Test Utility | Configuring firewalls | LiveKit docs | Firewall Tips
g
{ "logs": [ { "level": "info", "message": "Connected to server, version 1.9.3." } ], "name": "WebSocketCheck", "status": 3, "description": "Connecting to signal connection via WebSocket" } { "logs": [ { "level": "info", "message": "udp 3.108.40.190:57437 host" }, { "level": "info", "message": "tcp 3.108.40.190:7881 host (passive)" }, { "level": "info", "message": "udp 172.18.0.1:50688 host (private)" }, { "level": "info", "message": "tcp 172.18.0.1:7881 host (private)" }, { "level": "info", "message": "udp 172.17.0.1:52598 host (private)" }, { "level": "info", "message": "tcp 172.17.0.1:7881 host (private)" }, { "level": "info", "message": "udp 3.108.40.190:54176 host" }, { "level": "info", "message": "tcp 3.108.40.190:7881 host (passive)" }, { "level": "info", "message": "tcp 172.18.0.1:7881 host (private)" }, { "level": "info", "message": "udp 172.18.0.1:50536 host (private)" }, { "level": "info", "message": "udp 172.17.0.1:53485 host (private)" }, { "level": "info", "message": "tcp 172.17.0.1:7881 host (private)" }, { "level": "warning", "message": "error with ICE candidate: 701 STUN host lookup received error. stun:global.stun.twilio.com:3478" } ], "name": "WebRTCCheck", "status": 3, "description": "Establishing WebRTC connection" } { "logs": [ { "level": "warning", "message": "No TURN servers configured." } ], "name": "TURNCheck", "status": 2, "description": "Can connect via TURN" }
t
Thanks — these ConnectionCheck results are helpful. What they show • WebSocket succeeded (connected to server). • WebRTC shows ICE candidates gathered (UDP hosts) but a STUN lookup error:
701 STUN host lookup received error: stun:global.stun.twilio.com:3478
. • TURNCheck warns: "No TURN servers configured." What this means • Signaling is fine. The peer connection failed to find a usable path because STUN lookups are failing and no TURN relay is available as a fallback. Without TURN, networks that block UDP or have restrictive NAT will fail to establish the media connection. Next steps (pick applicable) • If you use LiveKit Cloud: ensure your client
wsUrl
points to the cloud instance (wss://...) and use tokens from that project — LiveKit Cloud provides TURN automatically. Rerun ConnectionCheck in the browser. • If self-hosted: configure TURN servers for your LiveKit deployment (or enable LiveKit’s TURN config). Add TURN servers to your LiveKit config so clients receive them in ICE candidates. • Temporary test: force TURN-only on the client to confirm relay fixes it:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
• Verify network/firewall: ◦ Allow TCP:443 to *.livekit.cloud and *.turn.livekit.cloud (or your TURN host). ◦ Open UDP 50000–60000 for direct media if you want ICE/UDP. • Re-run checks in the browser and paste these three results:
checkWebsocket
,
checkWebRTC
,
checkTURN
. If you tell me whether your LiveKit is cloud-hosted or self-hosted and paste your client
room.connect(wsUrl, token, ...)
call, I’ll give exact TURN config and follow-up steps.
g
so i have 2 livekit servers running under load balancer. how do i add turn server? and is that really needed?
t
Good questions — short answers first, then exact steps. Do you need TURN? • Yes when clients are behind restrictive NATs/firewalls or UDP is blocked. TURN provides a reliable relay (over TCP/TLS) so media can flow even when direct ICE/UDP fails. Without TURN, some users (corporate networks, strict carriers) will not connect. How to add TURN in a load‑balanced, multi‑server setup 1. Choose a TURN server • Use a hosted TURN (e.g., coturn on a public IP or a managed TURN provider) reachable by clients. • TURN must be accessible on TCP 443 (TLS) for maximum compatibility. 1. Configure LiveKit to advertise TURN • Configure the same TURN server(s) in your LiveKit config on every LiveKit node so ICE candidates include the TURN relay. Example fields to set in LiveKit config: ◦ turn.uris (e.g., ["turns:turn.example.com:443"]) ◦ turn.username / turn.password ◦ turn.tls = true (if using TLS) • Restart each LiveKit node after updating config. 1. Load balancer considerations • Keep the TURN service separate from the LiveKit nodes (clients should contact TURN directly). The load balancer stays in front of your LiveKit signaling/websocket endpoints only. • Ensure DNS for TURN points directly to the TURN server(s), not through the LiveKit load balancer. 1. Firewall and ports • Allow TCP 443 to your TURN host(s) and LiveKit nodes. • If you want direct UDP media, open UDP range 50000–60000 on LiveKit nodes and any NAT in front of them. 1. Verify • Run ConnectionCheck in the browser after config change; TURNCheck should show a usable TURN server. • Optionally force
iceTransportPolicy: 'relay'
in the client to confirm TURN relay works. Quick config example (coturn + LiveKit) • coturn: configure
tls-listening-port=443
,
listening-ip=PUBLIC_IP
,
realm=your-domain
, user credential or long-term-credentials. • LiveKit: set
turn.uris=["turns:turn.your-domain:443"]
,
turn.username
,
turn.password
,
turn.tls=true
. If you tell me: • whether you’ll use a hosted TURN or self-host coturn, and • whether LiveKit is cloud or self-hosted behind your LB, I’ll provide the exact LiveKit config snippet and a minimal coturn config you can apply.
g
i will use self host turn and i am using self hosted livekit behind ALB
t
Great — since you’re self‑hosting both TURN (coturn) and LiveKit behind an ALB, here are concise, actionable steps and configs to get TURN working reliably. Why TURN is required • TURN is needed for clients behind restrictive NATs/firewalls or when UDP is blocked. TURN over TLS (TCP 443) ensures media can relay even when direct ICE/UDP fails. High-level setup 1. Deploy coturn on a public IP (or public-facing instance). 2. Configure coturn to listen on TLS/TCP 443 and provide credentials. 3. Configure every LiveKit node (all nodes behind the ALB) to advertise the same TURN URIs and credentials. 4. Ensure DNS for your TURN hostname points directly to the TURN server (not through ALB). 5. Open necessary firewall ports. Minimal coturn config (important bits) • Use long-term credentials (recommended) and TLS on 443. Example options you can put in /etc/turnserver.conf: --listening-port=443 --tls-listening-port=443 --listening-ip=PUBLIC_IP --external-ip=PUBLIC_IP --realm=your-turn-domain.com --cert=/path/to/fullchain.pem --pkey=/path/to/privkey.pem --use-auth-secret --static-auth-secret=YOUR_SECRET # or use --lt-cred-mech with user accounts --no-stdout-log --log-file=/var/log/turnserver.log --fingerprint Notes: • Use valid TLS certs (Let’s Encrypt works). Ensure coturn can read cert & key. • Prefer long-term credential mechanism with a shared secret or dynamic username/password generation. LiveKit config (on each node) • Add TURN info so the server advertises relays to clients. Example YAML fragment: turn: uris: • "turns:turn.your-domain.com:443" username: "turn-user" # or leave blank if using shared secret approach password: "turn-password" tls: true • If using
use-auth-secret
in coturn (recommended), configure LiveKit to use TURN credentials that match your credential scheme (static username/password or dynamic credentials depending on your setup). DNS & ALB notes • TURN DNS (turn.your-domain.com) must resolve directly to the TURN server's public IP (not the ALB). • ALB remains in front of LiveKit signaling/websocket endpoints only (wss://). Do not route TURN through the ALB. • Ensure ALB health checks and stickiness (if used) are configured for LiveKit signaling as needed. Firewall / Ports • Allow TCP 443 to: ◦ LiveKit nodes (ALB → LiveKit for signaling) ◦ TURN server (clients → TURN) • For direct media (optional), allow UDP 50000–60000 to LiveKit nodes. • Ensure NAT / security groups map PUBLIC_IP → coturn instance. Testing and verification 1. From browser client run ConnectionCheck (in browser): ◦
checkWebsocket()
,
checkWebRTC()
,
checkTURN()
◦ TURNCheck should show your TURN server and pass. 1. Force relay on client to validate TURN:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
1. Check coturn logs for successful allocations and auths. Common pitfalls • TURN domain resolving to ALB (causes failure) — ensure direct DNS to TURN host. • Invalid TLS certs for coturn or LiveKit (verify with openssl s_client). • Coturn not bound to public IP / firewall blocking 443. • Using short-lived tokens or wrong credentials to authenticate to TURN (match mechanism). If you want, tell me: • the TURN hostname you plan to use (or confirm it will point to the TURN server public IP), • whether you’ll use static username/password or long-term secret (
use-auth-secret
), and I’ll give the exact LiveKit YAML snippet and a sample coturn.conf tuned for your choices.
g
So, I have a coturn server running on another ec2 machine. How do i update my existing livekit.yaml file to include the turn configs?
t
Good — since your coturn is on a separate EC2, update each LiveKit node’s
livekit.yaml
so clients receive TURN candidates. Below is a concise example and checklist. Example
livekit.yaml
TURN section (add under top-level config):
Copy code
turn:
  enabled: true
  uris:
    - "turns:turn.your-domain.com:443"    # TLS/TCP TURN
    - "turn:turn.your-domain.com:3478"    # UDP TURN (optional)
  username: "turn-user"                  # static username (or omit if using auth-secret)
  credential: "turn-password"            # password for static creds
  tls: true                              # advertise TLS TURN
If you use coturn long-term-credential secret (recommended) • In coturn: enable
--use-auth-secret
/
static-auth-secret=YOUR_SECRET
. • In LiveKit YAML, do not set `username`/`credential`; instead LiveKit will generate ephemeral TURN creds using the shared secret. Example:
Copy code
turn:
  enabled: true
  uris:
    - "turns:turn.your-domain.com:443"
  auth_secret: "YOUR_SECRET"
  tls: true
Checklist after editing • Ensure
turn.your-domain.com
DNS points directly to the coturn EC2 public IP (do NOT point to the ALB). • Coturn must have a valid TLS cert (for
turns:
on 443) and be reachable on the ports you advertise. • Open firewall/security group: ◦ TCP 443 to coturn (clients → TURN) ◦ UDP 3478 (optional) and/or UDP 50000–60000 (if using UDP media directly on LiveKit nodes) • Restart each LiveKit node after updating
livekit.yaml
. Verify 1. From a browser client, run ConnectionCheck
checkTURN()
and
checkWebRTC()
. TURNCheck should list your TURN server and pass. 2. Force relay test:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
1. Check coturn logs for allocations/auth attempts when clients connect. If you tell me whether you want static username/password or the
auth_secret
method, I’ll give the exact YAML lines and a minimal coturn.conf snippet for that mode. Sources: Deploying LiveKit | LiveKit docs | Deploy to Kubernetes | LiveKit docs
g
getting these errors: ov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 13: field tls not found in type config.TURNConfig Nov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 14: field shared_secret not found in type config.TURNConfig Nov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | could not parse config: yaml: unmarshal errors: Nov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 11: field uris not found in type config.TURNConfig Nov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 13: field tls not found in type config.TURNConfig Nov 27 054528 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 14: field shared_secret not found in type config.TURNConfig Nov 27 054529 ip-172-31-41-251 docker-compose[16441]: livekit-1 | could not parse config: yaml: unmarshal errors: Nov 27 054529 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 11: field uris not found in type config.TURNConfig Nov 27 054529 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 13: field tls not found in type config.TURNConfig Nov 27 054529 ip-172-31-41-251 docker-compose[16441]: livekit-1 | line 14: field shared_secret not found in type config.TURNConfig
t
Thanks — the errors mean your
turn
block used invalid field names. Use LiveKit’s supported schema. Based on the logs earlier you’re running a recent self-hosted server, so update each node’s
livekit.yaml
turn section to one of these valid options. If LiveKit should handle TURN/TLS (coturn DNS points to coturn server public IP)
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
  cert_file: /etc/letsencrypt/live/turn.your-domain.com/fullchain.pem
  key_file:  /etc/letsencrypt/live/turn.your-domain.com/privkey.pem
If your ALB terminates TLS and forwards plaintext to LiveKit (omit certs)
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
Notes and checks • Do NOT use
uris
,
tls
,
shared_secret
,
username
, or
credential
fields in LiveKit config — those caused the YAML parse errors. • Ensure
turn.your-domain.com
DNS resolves directly to the coturn EC2 public IP (must NOT point to the ALB). • Coturn should be configured independently (listening on 443 with valid TLS certs or long-term credential secret). • Open firewall/security groups: ◦ TCP 443 to coturn (clients → TURN) ◦ TCP 443 to ALB → LiveKit (signaling) ◦ UDP 50000–60000 to LiveKit nodes (if using direct UDP media) • Mount cert paths into the LiveKit container if you set `cert_file`/`key_file`. After editing 1. Restart LiveKit containers on each node. 2. From a browser client run ConnectionCheck:
checkWebsocket()
,
checkWebRTC()
,
checkTURN()
. TURNCheck should show your TURN server. 3. For quick verification, force relay:
Copy code
await room.connect(wsUrl, token, { rtcConfig: { iceTransportPolicy: 'relay' } });
If you want, paste: • your current
turn
block (exact lines), • the LiveKit server version (
livekit-server --version
), and I’ll give the exact YAML to apply and a minimal coturn.conf tuned for your setup. Sources: Ports and firewall | LiveKit docs | Deploy to a VM | LiveKit docs
g
2025-11-27T060058.813Z INFO livekit rtcconfig/ip.go:195 found external IP via STUN {"localAddr": "172.17.0.1:57448", "stunServer": "global.stun.twilio.com:3478", "externalIP": "65.0.72.28"} 2025-11-27T060058.813Z INFO livekit rtcconfig/ip.go:195 found external IP via STUN {"localAddr": "172.31.41.251:57448", "stunServer": "global.stun.twilio.com:3478", "externalIP": "65.0.72.28"} 2025-11-27T060058.813Z INFO livekit rtcconfig/ip.go:195 found external IP via STUN {"localAddr": "172.18.0.1:57448", "stunServer": "global.stun.twilio.com:3478", "externalIP": "65.0.72.28"} 2025-11-27T060059.814Z WARN livekit rtcconfig/ip.go:278 could not validate external IP {"ip": "65.0.72.28", "from": "172.18.0.1:57448", "error": "context canceled"} 2025-11-27T060059.813Z WARN livekit rtcconfig/ip.go:278 could not validate external IP {"ip": "65.0.72.28", "from": "172.17.0.1:57448", "error": "context canceled"} 2025-11-27T060059.815Z INFO livekit rtcconfig/webrtc_config.go:284 failed to get external ip {"local": "172.18.0.1", "err": "context canceled"} 2025-11-27T060059.815Z INFO livekit rtcconfig/webrtc_config.go:284 failed to get external ip {"local": "172.17.0.1", "err": "context canceled"} 2025-11-27T060059.815Z INFO livekit rtcconfig/webrtc_config.go:102 using external IPs {"ips": ["65.0.72.28/172.31.41.251", "172.17.0.1/172.17.0.1", "172.18.0.1/172.18.0.1"]} TURN tls cert required: open : no such file or directory
t
Thanks — the logs are useful. Two issues to fix: LiveKit can't find the TURN TLS cert, and external-IP validation is timing out. Quick steps to resolve both. 1) TURN TLS cert error • Error: "TURN tls cert required: open : no such file or directory" — LiveKit expected cert paths but they are missing or not mounted. • Fixes (pick one): ◦ If LiveKit should serve TURN/TLS directly: put valid cert files in the container and point livekit.yaml to them:
Copy code
turn:
      enabled: true
      domain: turn.your-domain.com
      tls_port: 443
      udp_port: 443
      cert_file: /etc/letsencrypt/live/turn.your-domain.com/fullchain.pem
      key_file: /etc/letsencrypt/live/turn.your-domain.com/privkey.pem
• Ensure those files exist in the container (mount host paths into the container in docker-compose). • If ALB terminates TLS (recommended with ALB): remove cert_file/key_file and let ALB handle TLS. Example:
Copy code
turn:
      enabled: true
      domain: turn.your-domain.com
      tls_port: 443
      udp_port: 443
• Important: turn.your-domain.com must resolve directly to your coturn EC2 public IP, not the ALB, because TURN clients must talk to coturn. 2) External IP / STUN warnings • Logs show LiveKit found external IP via STUN (65.0.72.28) but validation timed out ("context canceled"). LiveKit then used a best-effort list of external IPs. • Likely causes: transient STUN lookup timeouts, firewall blocking outbound STUN, or short time budget for validation. • Fixes: ◦ Ensure LiveKit nodes can reach public STUN/TURN servers (UDP/TCP) outbound. ◦ If using coturn for external IP discovery, confirm coturn is reachable and responsive. ◦ Consider setting
use_external_ip: true
and explicitly providing the public IP in
rtc.use_external_ip
or
rtc.external_ips
if NAT is static:
Copy code
rtc:
      use_external_ip: true
      external_ip: 65.0.72.28
(Use only if your public IP is static for each node.) • Open outbound UDP/TCP as needed and retry — STUN validation should then succeed. 3) Coturn + LiveKit notes (quick checklist) • coturn runs on EC2 public IP with valid TLS certs for turn.your-domain.com. • DNS: turn.your-domain.com → coturn public IP (not ALB). • Firewall: allow TCP 443 to coturn; allow UDP 50000–60000 to LiveKit nodes (or use TLS TURN only). • Mount certs into LiveKit container if LiveKit is serving TURN TLS. 4) Next steps I can do for you • If you paste your current
turn:
and
rtc:
sections from livekit.yaml and your docker-compose mount paths, I’ll give exact corrected YAML and docker-compose volume mappings. • Tell me if TLS is terminated at the ALB or if LiveKit/coturn should handle TLS.
g
cert_file: /etc/letsencrypt/live/turn.your-domain.com/fullchain.pem key_file: /etc/letsencrypt/live/turn.your-domain.com/privkey.pem These files are on my turn ec2 instance right?
t
If LiveKit is running on different hosts than your coturn EC2, those cert files must be accessible to the LiveKit process — not just present on the TURN EC2. Options: 1) ALB or coturn handle TLS (recommended) • Keep certs on the coturn EC2 (and/or ALB). In LiveKit config omit `cert_file`/`key_file`:
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
• DNS for turn.your-domain.com must point directly to the coturn EC2 public IP (clients talk to coturn). ALB terminates TLS for LiveKit signaling only. 2) LiveKit serves TURN/TLS directly • Copy or mount the cert files into each LiveKit node and point `cert_file`/`key_file` to local paths inside the LiveKit container:
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
  cert_file: /etc/letsencrypt/live/turn.your-domain.com/fullchain.pem
  key_file: /etc/letsencrypt/live/turn.your-domain.com/privkey.pem
• In docker-compose, mount host cert dir into the container:
Copy code
volumes:
  - /etc/letsencrypt/live/turn.your-domain.com:/etc/letsencrypt/live/turn.your-domain.com:ro
• Ensure certs are valid for the turn domain and restart LiveKit. Which to choose • Use option 1 if coturn already has certs and you want a simpler setup (LiveKit nodes do not need certs). • Use option 2 only if LiveKit must terminate TURN/TLS itself. Tell me which option you prefer and whether LiveKit or coturn is terminating TLS; I’ll give the exact docker-compose volume mounts and final livekit.yaml snippet.
g
but if i dont sepcify the cert file path, then livekit nodes throws error
t
Thanks — that error means LiveKit expects cert paths when
turn.enabled: true
and no TLS termination is configured upstream. Quick options to fix it: 1) Prefered — let coturn terminate TURN/TLS (recommended) • Keep certs only on the coturn EC2. • In each LiveKit node's
livekit.yaml
omit `cert_file`/`key_file` and only set:
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
• Ensure DNS for
turn.your-domain.com
points directly to the coturn EC2 public IP (clients connect to coturn), and coturn has the certs. Restart LiveKit. LiveKit will still advertise TURN, but clients will use the coturn server you configured. 2) If LiveKit must serve TURN/TLS (you chose this), provide certs on every LiveKit node • Copy or mount the certs into each LiveKit container and set paths in
livekit.yaml
. • Example docker-compose volume (host certs on each node):
Copy code
services:
  livekit:
    image: livekit/livekit-server:latest
    volumes:
      - /etc/letsencrypt/live/turn.your-domain.com:/etc/letsencrypt/live/turn.your-domain.com:ro
• livekit.yaml:
Copy code
turn:
  enabled: true
  domain: turn.your-domain.com
  tls_port: 443
  udp_port: 443
  cert_file: /etc/letsencrypt/live/turn.your-domain.com/fullchain.pem
  key_file:  /etc/letsencrypt/live/turn.your-domain.com/privkey.pem
• Restart containers. The cert files must exist inside the container at those exact paths. Why omitting certs caused the error • LiveKit detected
turn.enabled: true
and expected TLS certs for TURN/TLS on that host. If you don’t provide certs and TLS isn’t terminated upstream, LiveKit fails to start. If you tell me which option you want (coturn handles TLS vs LiveKit handles TLS), I’ll give the exact livekit.yaml and docker-compose changes for your setup and a short checklist to verify.
g
see my coturn in on different ec2 and livekit is on different ec2. what should i do now?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
g
TURN tls cert required: open : no such file or directory My coturn is on different ec2 and livekit server is on different ec2. how can i set the path of the cert files in livekit.yaml file?
can u help on the above?