{"record":{"id":"223acad254785457","repo":"router-for-me/CLIProxyAPI","slug":"create-downstream-peerconnection-w","errorCode":null,"errorMessage":"create downstream PeerConnection: %w","messagePattern":"create downstream PeerConnection: %w","errorType":"http","errorClass":null,"httpStatus":502,"severity":"error","filePath":"internal/client/codex/live/media.go","lineNumber":287,"sourceCode":"\t\treturn nil, \"\", fmt.Errorf(\"configure Codex live remote TCP proxy: %w\", errProxy)\n\t}\n\tproxied := proxyMode == proxyutil.ModeProxy\n\tvar proxyDialer proxy.ContextDialer\n\tif proxied {\n\t\tcontextDialer, ok := builtProxyDialer.(proxy.ContextDialer)\n\t\tif !ok {\n\t\t\treturn nil, \"\", errors.New(\"Codex live remote TCP proxy does not support cancellation\")\n\t\t}\n\t\tproxyDialer = contextDialer\n\t}\n\tif !r.limiter.acquire() {\n\t\treturn nil, \"\", errors.New(\"Codex live media relay capacity exhausted\")\n\t}\n\treleaseSlot := r.limiter.release\n\tdownstream, errDownstream := r.downstreamAPI.NewPeerConnection(r.configuration)\n\tif errDownstream != nil {\n\t\treleaseSlot()\n\t\treturn nil, \"\", fmt.Errorf(\"create downstream PeerConnection: %w\", errDownstream)\n\t}\n\tupstreamAPI := r.upstreamAPI\n\tupstreamConfiguration := r.configuration\n\tif proxied {\n\t\tupstreamAPI = r.proxyUpstreamAPI\n\t\tupstreamConfiguration.ICEServers = nil\n\t}\n\tupstream, errUpstream := upstreamAPI.NewPeerConnection(upstreamConfiguration)\n\tif errUpstream != nil {\n\t\treleaseSlot()\n\t\tif errClose := downstream.Close(); errClose != nil {\n\t\t\tlog.WithError(errClose).Debug(\"codex live media: close downstream PeerConnection after setup error\")\n\t\t}\n\t\treturn nil, \"\", fmt.Errorf(\"create upstream PeerConnection: %w\", errUpstream)\n\t}\n\n\tsession := &pionMediaSession{\n\t\tdownstream:     downstream,","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/client/codex/live/media.go#L269-L305","documentation":"Thrown when r.downstreamAPI.NewPeerConnection(r.configuration) fails while creating the peer connection facing the local client. Pion returns errors for invalid ICE server URLs, bad STUN/TURN configuration, or an expired/closed API object. The limiter slot acquired just before is released via releaseSlot(). This is the first PeerConnection of the two the relay creates per session.","triggerScenarios":"An ICE server entry in relayConfig.ICEServers with a malformed URL (wrong scheme, bad port), a TURN credential type mismatch, or resource exhaustion (socket/ICE agent creation failure) at session start.","commonSituations":"Bad stun:/turn: URL in the media relay config, TURN server password errors surfaced at PC creation, or transient fd exhaustion on a loaded host.","solutions":["Validate every ICE server URL in codex-live-media-relay config (scheme stun/turn/turns, resolvable host, valid port)","Retry the call once — ICE agent setup can fail transiently under fd/memory pressure","Check host resource limits (ulimit -n) if failures cluster under load","Verify credentials for TURN servers are current"],"exampleFix":"# before\ncodex-live-media-relay:\n  ice-servers:\n    - urls: [\"turn turn.example.com\"]\n\n# after\ncodex-live-media-relay:\n  ice-servers:\n    - urls: [\"turn:turn.example.com:3478?transport=udp\"]\n      username: user\n      credential: pass","handlingStrategy":"retry","validationCode":"for _, server := range relayConfig.ICEServers {\n\tfor _, raw := range server.URLs {\n\t\tu, err := url.Parse(strings.TrimSpace(raw))\n\t\tif err != nil || (u.Scheme != \"stun\" && u.Scheme != \"turn\" && u.Scheme != \"turns\") {\n\t\t\treturn fmt.Errorf(\"invalid ICE server URL %q\", raw)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"var downstream *webrtc.PeerConnection\nvar errDownstream error\nfor attempt := 0; attempt < 2; attempt++ {\n\tdownstream, errDownstream = api.NewPeerConnection(cfg)\n\tif errDownstream == nil {\n\t\tbreak\n\t}\n}","preventionTips":["Validate ICE server URLs at config load","Monitor fd usage on the host running the relay","Keep TURN credentials fresh and monitored"],"tags":["webrtc","pion","ice","stun","turn","configuration"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}