{"record":{"id":"b49cb388de1e64ac","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-reset-deadline-w","errorCode":null,"errorMessage":"cannot reset deadline: %w","messagePattern":"cannot reset deadline: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/handshake/handshake.go","lineNumber":229,"sourceCode":"\tif err := writeMessage(c, successResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot write success response on isCompressed: %w\", err)\n\t}\n\tisRemoteCompressed, err := readIsCompressed(c)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot read isCompressed flag: %w\", err)\n\t}\n\tif err := writeMessage(c, successResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot write success response on isCompressed: %w\", err)\n\t}\n\tif err := writeIsCompressed(c, compressionLevel > 0); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot write isCompressed flag: %w\", err)\n\t}\n\tif err := readMessage(c, successResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot read success response on isCompressed: %w\", err)\n\t}\n\n\tif err := c.SetDeadline(time.Time{}); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot reset deadline: %w\", err)\n\t}\n\n\tbc := newBufferedConn(c, compressionLevel, isRemoteCompressed)\n\treturn bc, nil\n}\n\nfunc genericClient(c net.Conn, msg string, compressionLevel int) (*BufferedConn, error) {\n\tif err := c.SetDeadline(time.Now().Add(*rpcHandshakeTimeout)); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot set deadline: %w\", err)\n\t}\n\n\tif err := writeMessage(c, msg); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot write hello: %w\", err)\n\t}\n\tif err := readMessage(c, successResponse); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot read success response after sending hello: %w\", err)\n\t}\n\tif err := writeIsCompressed(c, compressionLevel > 0); err != nil {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/handshake/handshake.go#L211-L247","documentation":"This error wraps a failure from `c.SetDeadline(time.Time{})` at the very end of genericServer, which clears the handshake timeout so the connection can be used for normal RPC traffic. The library throws it when the underlying net.Conn refuses or fails the deadline-reset call after a successful handshake exchange. In practice this only happens on already-broken connections (closed, unsupported conn types, or internal deadline bookkeeping failures), since clearing a deadline rarely fails on a healthy TCP conn.","triggerScenarios":"Any call into genericServer — VMInsertServer, VMInsertServerWithLegacyHello, or VMSelectServer — where the server-side handshake completed (hello read, success responses written, isCompressed flags exchanged) but the final SetDeadline(zero) call returns an error, typically because the peer closed the connection mid-handshake or the conn is in an error state.","commonSituations":"The client disconnected immediately after the last handshake byte (race between handshake completion and client teardown); a proxy/LB killed the connection between the last read and the deadline reset; a custom net.Conn wrapper that mishandles SetDeadline is used in tests or custom transports.","solutions":["Check client-side logs for why the peer closed the connection during handshake; fix the client that hangs up early.","Verify any custom net.Conn implementation correctly supports SetDeadline (including time.Time{} to clear).","Rule out intermediaries (load balancers, k8s probes) with short idle/close timeouts that race with handshake completion.","Retry the connection; this error is transient when caused by a disconnect race."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// client side: ensure the conn stays open through the whole handshake\nif err := conn.SetDeadline(time.Now().Add(timeout)); err != nil {\n    return fmt.Errorf(\"conn unusable before handshake: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"bc, err := handshake.VMSelectServer(conn, compressionLevel)\nif err != nil {\n    if strings.Contains(err.Error(), \"cannot reset deadline\") {\n        // transient peer disconnect; re-accept/retry\n        return retryAccept()\n    }\n    return err\n}","preventionTips":["Avoid closing client conns immediately after sending handshake data","Set LB/proxy idle timeouts comfortably above rpcHandshakeTimeout","Use standard *net.TCPConn or wrappers that fully implement SetDeadline","Treat post-handshake deadline-reset failures as transient and retry"],"tags":["go","network","rpc","handshake","victoriametrics"],"backgroundTag":"handshake-deadline-reset-failed","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}