{"record":{"id":"6f703351267f5938","repo":"AlexxIT/go2rtc","slug":"dtls-server-handshake-failed-w","errorCode":null,"errorMessage":"dtls: server handshake failed: %w","messagePattern":"dtls: server handshake failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tutk/dtls/conn_dtls.go","lineNumber":232,"sourceCode":"\t\t\t\t\t\t\t\tack := c.msgACK()\n\t\t\t\t\t\t\t\tc.clientConn.Write(ack)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}()\n\n\t\t\t\treturn nil\n\t\t\t}\n\t\tcase <-timer.C:\n\t\t\treturn context.DeadlineExceeded\n\t\t}\n\t}\n}\n\nfunc (c *DTLSConn) AVServStart() error {\n\tconn, err := NewDTLSServer(c.ctx, iotcChannelBack, c.addr, c.WriteDTLS, c.serverBuf, c.psk)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"dtls: server handshake failed: %w\", err)\n\t}\n\n\tif c.verbose {\n\t\tfmt.Printf(\"[DTLS] Server handshake complete on channel %d\\n\", iotcChannelBack)\n\t\tfmt.Printf(\"[SERVER] Waiting for AV Login request from camera...\\n\")\n\t}\n\n\t// Wait for AV Login request from camera\n\tbuf := make([]byte, 1024)\n\tconn.SetReadDeadline(time.Now().Add(5 * time.Second))\n\tn, err := conn.Read(buf)\n\tif err != nil {\n\t\tgo conn.Close()\n\t\treturn fmt.Errorf(\"read av login: %w\", err)\n\t}\n\n\tif c.verbose {\n\t\tfmt.Printf(\"[SERVER] AV Login request len=%d data:\\n%s\", n, hexDump(buf[:n]))","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tutk/dtls/conn_dtls.go#L214-L250","documentation":"AVServStart acts as the DTLS server on the back channel and wraps any failure of NewDTLSServer (the PSK-based DTLS server handshake) with this error. It means the DTLS server-side handshake with the camera did not complete, so the AV login exchange cannot proceed.","triggerScenarios":"Calling StartIntercom -> AVServStart when NewDTLSServer fails: wrong PSK, client (camera) never initiates the DTLS handshake, or the underlying pion/dtls listener errors.","commonSituations":"PSK mismatch between host and camera firmware; camera not attempting to connect on the back channel; UDP path blocked so handshake packets never arrive; certificate/cipher suite incompatibility in the DTLS stack.","solutions":["Verify the PSK matches the one derived from the device credentials","Check that the camera is online and initiating contact on the back channel","Confirm UDP traffic is not blocked by firewall/NAT","Enable verbose logging to see how far the handshake progressed"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if psk == nil || len(psk) == 0 {\n\treturn fmt.Errorf(\"missing DTLS PSK\")\n}","typeGuard":null,"tryCatchPattern":"if err := conn.AVServStart(); err != nil {\n\tvar he *dtls.HandshakeError\n\tif errors.As(err, &he) {\n\t\t// re-run StartIntercom after verifying PSK\n\t}\n\treturn err\n}","preventionTips":["Verify PSK derivation matches the device credentials before starting the server","Confirm the camera initiated the back-channel before calling AVServStart","Check firewall/NAT for UDP path availability","Use verbose mode to observe handshake progress"],"tags":["dtls","handshake","psk","network"],"backgroundTag":"handshake-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"}