{"record":{"id":"fa27e75bba259bf9","repo":"AlexxIT/go2rtc","slug":"err-error-fa27e7","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/dvrip/dvrip.go","lineNumber":28,"sourceCode":"\n\t\"github.com/AlexxIT/go2rtc/internal/api\"\n\t\"github.com/AlexxIT/go2rtc/internal/streams\"\n\t\"github.com/AlexxIT/go2rtc/pkg/dvrip\"\n)\n\nfunc Init() {\n\tstreams.HandleFunc(\"dvrip\", dvrip.Dial)\n\n\t// DVRIP client autodiscovery\n\tapi.HandleFunc(\"api/dvrip\", apiDvrip)\n}\n\nconst Port = 34569 // UDP port number for dvrip discovery\n\nfunc apiDvrip(w http.ResponseWriter, r *http.Request) {\n\titems, err := discover()\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tapi.ResponseSources(w, items)\n}\n\nfunc discover() ([]*api.Source, error) {\n\taddr := &net.UDPAddr{\n\t\tPort: Port,\n\t\tIP:   net.IP{239, 255, 255, 250},\n\t}\n\n\tconn, err := net.ListenUDP(\"udp4\", addr)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdefer conn.Close()","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/dvrip/dvrip.go#L10-L46","documentation":"apiDvrip handles the dvrip discovery API endpoint: it calls discover(), which broadcasts on UDP port 34569 to find Dahua-style IP cameras. If discovery returns an error (typically failure to bind or send/receive on the UDP socket), err.Error() is returned with HTTP 500. The library surfaces the raw socket error so network problems are visible.","triggerScenarios":"GET on the dvrip API when the UDP broadcast fails: no network interface can send the broadcast packet, binding to port 34569 fails (port in use or permission denied), or the socket operations return an OS error.","commonSituations":"Running inside a Docker bridge network where UDP broadcasts do not propagate, firewall rules blocking outbound UDP broadcast, missing SO_BROADCAST privileges, or running on a host with no active network interface.","solutions":["Check the error text in the 500 response — it names the failing socket operation","Ensure the host has an active network interface and the firewall allows outbound UDP broadcasts (port 34569)","If in Docker, use host networking (--network host) so UDP broadcasts reach the LAN","Verify nothing else is bound to UDP port 34569 (ss -ulpn | grep 34569)","Retry discovery; transient interface-down states (Wi-Fi reconnect) can cause failures"],"exampleFix":"// before\ndocker run -p 1984:1984 go2rtc\n// after\ndocker run --network host go2rtc","handlingStrategy":"try-catch","validationCode":"// client-side precheck: is UDP broadcast viable on this interface?\niface, err := net.InterfaceByName(\"eth0\")\nif err != nil || (iface.Flags&net.FlagUp) == 0 || (iface.Flags&net.FlagBroadcast) == 0 {\n    // discovery will likely fail; fix network first\n}","typeGuard":null,"tryCatchPattern":"resp, err := http.Get(baseURL + \"/api/dvrip\")\nif err == nil && resp.StatusCode == http.StatusInternalServerError {\n    b, _ := io.ReadAll(resp.Body)\n    log.Printf(\"dvrip discovery failed: %s — retrying with host network/firewall fix\", string(b))\n}","preventionTips":["Use --network host in Docker for UDP-based discovery protocols","Allow outbound UDP broadcasts through the host firewall","Ensure at least one interface is up before calling discovery","Check nothing else occupies UDP port 34569","Retry discovery after interface changes (Wi-Fi reconnect, VPN up)"],"tags":["network","udp","discovery","http"],"backgroundTag":"network-request-failed","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}