{"record":{"id":"c0c6201bb9f3d033","repo":"router-for-me/CLIProxyAPI","slug":"configure-webrtc-udp-port-range-w","errorCode":null,"errorMessage":"configure WebRTC UDP port range: %w","messagePattern":"configure WebRTC UDP port range: %w","errorType":"http","errorClass":null,"httpStatus":503,"severity":"error","filePath":"internal/client/codex/live/media.go","lineNumber":226,"sourceCode":"}\n\nfunc newPionAPIWithOptions(relayConfig config.CodexLiveMediaRelayConfig, filterPrivateRemoteIPs, loopbackOnly bool) (*webrtc.API, error) {\n\tmediaEngine := &webrtc.MediaEngine{}\n\tif errRegister := mediaEngine.RegisterCodec(webrtc.RTPCodecParameters{\n\t\tRTPCodecCapability: opusCodec,\n\t\tPayloadType:        111,\n\t}, webrtc.RTPCodecTypeAudio); errRegister != nil {\n\t\treturn nil, fmt.Errorf(\"register Opus codec: %w\", errRegister)\n\t}\n\tinterceptorRegistry := &interceptor.Registry{}\n\tif errRegister := webrtc.RegisterDefaultInterceptors(mediaEngine, interceptorRegistry); errRegister != nil {\n\t\treturn nil, fmt.Errorf(\"register WebRTC interceptors: %w\", errRegister)\n\t}\n\tsettingEngine := webrtc.SettingEngine{}\n\tif !loopbackOnly {\n\t\tif relayConfig.UDPPortMin != 0 {\n\t\t\tif errPorts := settingEngine.SetEphemeralUDPPortRange(relayConfig.UDPPortMin, relayConfig.UDPPortMax); errPorts != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"configure WebRTC UDP port range: %w\", errPorts)\n\t\t\t}\n\t\t}\n\t\tif publicIP := strings.TrimSpace(relayConfig.PublicIP); publicIP != \"\" {\n\t\t\tsettingEngine.SetNAT1To1IPs([]string{publicIP}, webrtc.ICECandidateTypeHost)\n\t\t}\n\t}\n\tif filterPrivateRemoteIPs {\n\t\tsettingEngine.SetRemoteIPFilter(isPublicRemoteIP)\n\t}\n\tif loopbackOnly {\n\t\tsettingEngine.SetNetworkTypes([]webrtc.NetworkType{\n\t\t\twebrtc.NetworkTypeUDP4,\n\t\t\twebrtc.NetworkTypeUDP6,\n\t\t\twebrtc.NetworkTypeTCP4,\n\t\t\twebrtc.NetworkTypeTCP6,\n\t\t})\n\t\tsettingEngine.SetIncludeLoopbackCandidate(true)\n\t\tsettingEngine.SetIPFilter(func(ip net.IP) bool {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/client/codex/live/media.go#L208-L244","documentation":"Thrown when SettingEngine.SetEphemeralUDPPortRange rejects the configured min/max port pair for the non-loopback Pion API. The pion API returns an error when min > max, when either port is outside 0-65535, or when the range includes privileged/invalid values. It comes from the codex-live-media-relay UDP port range config (UDPPortMin/UDPPortMax), only applied when not loopback-only and UDPPortMin != 0.","triggerScenarios":"Configuring relayConfig.UDPPortMin > relayConfig.UDPPortMax, setting a port above 65535 or negative, or setting only UDPPortMin while UDPPortMax stays 0 (min>max).","commonSituations":"YAML config typos in the media relay port range, swapping min and max keys, copying a range like 50000-40000, or setting UDPPortMin without UDPPortMax.","solutions":["Fix config so 0 < UDPPortMin <= UDPPortMax <= 65535 (e.g. min 50000, max 51000)","Leave both unset (0) if you do not need a pinned UDP range — the code skips SetEphemeralUDPPortRange entirely","Check config.CodexLiveMediaRelayConfig.Validate() if adding range validation so this fails at config load, not at relay construction"],"exampleFix":"# before (config.yaml)\ncodex-live-media-relay:\n  udp-port-min: 61000\n  udp-port-max: 50000\n\n# after\ncodex-live-media-relay:\n  udp-port-min: 50000\n  udp-port-max: 61000","handlingStrategy":"validation","validationCode":"if relayConfig.UDPPortMin != 0 {\n\tif relayConfig.UDPPortMin < 1 || relayConfig.UDPPortMax < relayConfig.UDPPortMin || relayConfig.UDPPortMax > 65535 {\n\t\treturn fmt.Errorf(\"invalid UDP port range %d-%d\", relayConfig.UDPPortMin, relayConfig.UDPPortMax)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always configure udp-port-min and udp-port-max as a pair","Add the range check to config validation so it fails at config load","Prefer leaving both unset unless firewall pinning requires them"],"tags":["webrtc","pion","configuration","network","ports"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}