{"record":{"id":"e1a1c2e16b8aa8d5","repo":"router-for-me/CLIProxyAPI","slug":"create-upstream-peerconnection-w","errorCode":null,"errorMessage":"create upstream PeerConnection: %w","messagePattern":"create upstream PeerConnection: %w","errorType":"http","errorClass":null,"httpStatus":502,"severity":"error","filePath":"internal/client/codex/live/media.go","lineNumber":301,"sourceCode":"\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,\n\t\tupstream:       upstream,\n\t\tdone:           make(chan struct{}),\n\t\tmediaSessionID: uuid.NewString(),\n\t\treleaseSlot:    releaseSlot,\n\t\tproxyDialer:    proxyDialer,\n\t\tproxyScheme:    proxyScheme(route.proxyURL),\n\t\tcredential:     strings.TrimSpace(route.credential),\n\t\tauthIndex:      strings.TrimSpace(route.authIndex),\n\t}\n\tsession.bridge = newDataChannelBridge(session.done, func(err error) {\n\t\tsession.fail(\"data_channel_failed\", err)\n\t})\n\tsession.installStateHandlers()\n\tlog.WithFields(session.logFields(\"session\")).Info(\"codex live WebRTC media session created\")","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/client/codex/live/media.go#L283-L319","documentation":"Thrown when the second PeerConnection (toward OpenAI's upstream) cannot be created — either the plain upstream API or, when a proxy is configured, proxyUpstreamAPI with ICEServers stripped. The downstream PeerConnection and the limiter slot are cleaned up before returning. Same pion failure classes as downstream creation, plus anything specific to the proxy-routed SettingEngine.","triggerScenarios":"Same as 323 but on the upstream leg; with proxied=true, failure is tied to the loopback-only proxy API configuration rather than ICE servers (they are nil'd for the proxy path).","commonSituations":"Malformed STUN/TURN URLs (non-proxied path), ICE agent creation failure on the loopback-only proxy API, or resource exhaustion while two PCs are being created back to back.","solutions":["Apply the same ICE server URL/credential validation as for the downstream leg","If using a proxy route, check the proxy itself is reachable and correctly configured (error 322 precedes this)","Retry once for transient ICE-agent creation failures","Raise max-sessions only after ruling out resource exhaustion (the limiter correctly frees the slot here)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if _, _, err := relay.NewSession(ctx, offer, route); err != nil {\n\tif strings.Contains(err.Error(), \"create upstream PeerConnection\") {\n\t\t// session state was cleaned up; safe to retry once\n\t\ttime.Sleep(100 * time.Millisecond)\n\t\t_, _, err = relay.NewSession(ctx, offer, route)\n\t}\n}","preventionTips":["Same ICE/resource hygiene as the downstream leg","Rely on NewSession's built-in cleanup (downstream Close + limiter release) rather than partial retries","Alert when both legs fail together — points at host-level resource issues"],"tags":["webrtc","pion","ice","upstream","cleanup"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}