{"record":{"id":"288b34a84a7af27b","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-iscompressed-flag-w","errorCode":null,"errorMessage":"cannot read isCompressed flag: %w","messagePattern":"cannot read isCompressed flag: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/handshake/handshake.go","lineNumber":216,"sourceCode":"\t}\n\n\treturn false\n}\n\nfunc genericServer(c net.Conn, compressionLevel int, readHelloMessage func(c net.Conn) error) (*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 := readHelloMessage(c); err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot read hello message : %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\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}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/handshake/handshake.go#L198-L234","documentation":"In genericServer, after writing the first successResponse the server reads the client's isCompressed flag with readIsCompressed(c). This error wraps whatever I/O error that read returned. It means the server could not read the single-byte compression flag from the client before the handshake deadline expired or the connection dropped.","triggerScenarios":"VMInsertServer/VMInsertServerWithLegacyHello/VMSelectServer accepted a connection and got past the hello exchange, but readIsCompressed(c) fails: the client closed the connection, sent a partial/short message (io.ErrUnexpectedEOF), or the rpcHandshakeTimeout deadline expired while waiting for the flag.","commonSituations":"Peer is not a VictoriaMetrics client and sends garbage or nothing after hello (wrong port, port scanner, monitoring probe); abrupt client termination; network partitions; handshake timeout too low for slow links; protocol/version mismatch where an older client never sends the isCompressed flag.","solutions":["Check the wrapped error: io.EOF/ErrUnexpectedEOF usually means the peer closed or is not speaking the expected protocol — verify the client is a compatible VictoriaMetrics version.","Raise -rpc.handshakeTimeout if the wrapped error is a timeout on high-latency links.","Confirm nothing between the peers (LB, service mesh, firewall) truncates or times out short-lived connections during handshake.","Filter these with handshake.IsClientNetworkError(err) so probes/scanners that hit the port do not pollute error logs."],"exampleFix":"// before\nbc, err := handshake.VMSelectServer(conn, compressionLevel)\nif err != nil {\n    return fmt.Errorf(\"handshake: %w\", err)\n}\n// after: distinguish dead/mismatched peers from timeouts\nbc, err := handshake.VMSelectServer(conn, compressionLevel)\nif err != nil {\n    if handshake.IsClientNetworkError(err) {\n        return nil // peer vanished mid-handshake; nothing to do server-side\n    }\n    return fmt.Errorf(\"handshake: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Client side: ensure you only dial the VictoriaMetrics RPC port and send the hello promptly\nconn.SetDeadline(time.Now().Add(handshakeTimeout))\nif _, err := handshake.VMInsertClient(conn, helloMsg, compressionLevel); err != nil {\n    return fmt.Errorf(\"peer does not speak the expected protocol: %w\", err)\n}","typeGuard":"func isCompressedFlagReadError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"cannot read isCompressed flag\")\n}","tryCatchPattern":"bc, err := handshake.VMSelectServer(conn, compressionLevel)\nif err != nil {\n    switch {\n    case errors.Is(err, io.EOF), errors.Is(err, io.ErrUnexpectedEOF):\n        return nil // peer closed early: probe, crash, or version mismatch\n    case handshake.IsTimeoutNetworkError(err):\n        return fmt.Errorf(\"handshake timeout, raise -rpc.handshakeTimeout: %w\", err)\n    }\n    return err\n}","preventionTips":["Verify you are dialing the correct VM RPC port — wrong ports produce peers that never send the flag.","Run compatible client/server versions; older clients may not send isCompressed.","Raise -rpc.handshakeTimeout on slow or high-latency links.","Rate-limit or firewall port scanners that hit the RPC port."],"tags":["network","handshake","rpc","compression"],"backgroundTag":"connection-reset-by-peer","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"}