{"record":{"id":"d59dad83f79d3fcb","repo":"AlexxIT/go2rtc","slug":"err-error-d59dad","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"internal/onvif/onvif.go","lineNumber":64,"sourceCode":"\n\t// Append hash-based arguments to the retrieved URI\n\tif i := strings.IndexByte(rawURL, '#'); i > 0 {\n\t\turi += rawURL[i:]\n\t}\n\n\tlog.Debug().Msgf(\"[onvif] new uri=%s\", uri)\n\n\tif err = streams.Validate(uri); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn streams.GetProducer(uri)\n}\n\nfunc onvifDeviceService(w http.ResponseWriter, r *http.Request) {\n\tb, err := io.ReadAll(r.Body)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\toperation := onvif.GetRequestAction(b)\n\tif operation == \"\" {\n\t\thttp.Error(w, \"malformed request body\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tlog.Trace().Msgf(\"[onvif] server request %s %s:\\n%s\", r.Method, r.RequestURI, b)\n\n\tswitch operation {\n\tcase onvif.ServiceGetServiceCapabilities, // important for Hass\n\t\tonvif.DeviceGetNetworkInterfaces, // important for Hass\n\t\tonvif.DeviceGetSystemDateAndTime, // important for Hass\n\t\tonvif.DeviceSetSystemDateAndTime, // return just OK\n\t\tonvif.DeviceGetDiscoveryMode,\n\t\tonvif.DeviceGetDNS,","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/internal/onvif/onvif.go#L46-L82","documentation":"go2rtc's ONVIF device-service endpoint (/onvif/) reads the entire SOAP request body with io.ReadAll before deciding how to respond. If reading the body fails mid-transfer, the handler converts the raw error string to an HTTP 500 response. This means the ONVIF client's request never arrived intact, so no ONVIF processing could be attempted.","triggerScenarios":"A client POSTs a SOAP request to /onvif/... and the TCP connection breaks or the request is aborted while the server is still reading the body (client disconnect, timeout, corrupted chunked transfer).","commonSituations":"Clients with aggressive timeouts dropping the connection mid-request; network interruptions between an NVR (e.g. Home Assistant) and go2rtc; HTTP proxies or load balancers terminating long-running uploads; rare client bugs sending invalid chunked encoding.","solutions":["Check the go2rtc logs and the client for a simultaneous connection-abort/timeout error at the same timestamp","Verify network stability (proxy, LB, docker networking) between the ONVIF client and go2rtc","Increase the client's request timeout so slow body uploads are not aborted","Retry the ONVIF request; transient disconnects are usually client-side"],"exampleFix":"// before (client side)\nreq, _ := http.NewRequest(\"POST\", url, body) // no timeout control\n// after (client side)\nclient := &http.Client{Timeout: 30 * time.Second}\nclient.Do(req)","handlingStrategy":"try-catch","validationCode":"// client side: ensure the request completes and the body is fully written before abandoning\nreq, _ := http.NewRequest(\"POST\", \"http://server:1984/onvif/\", bytes.NewReader(soapBody))\nreq.Header.Set(\"Content-Type\", \"application/soap+xml\")","typeGuard":null,"tryCatchPattern":"resp, err := client.Do(req)\nif err != nil {\n    // retry once on transport failure before surfacing\n    resp, err = client.Do(req)\n    if err != nil { return fmt.Errorf(\"onvif request failed: %w\", err) }\n}\nif resp.StatusCode == http.StatusInternalServerError {\n    // server failed reading our body: likely our connection dropped; retry\n}","preventionTips":["Set generous client timeouts for ONVIF POSTs","Keep ONVIF client and go2rtc on the same stable LAN segment","Avoid proxies that idle-timeout long SOAP requests","Monitor for repeated disconnect patterns in logs"],"tags":["http","network","onvif"],"backgroundTag":"http-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"}