{"record":{"id":"45b87192e0d584fb","repo":"t8y2/dbx","slug":"decode-zookeeper-session-id-w","errorCode":null,"errorMessage":"decode ZooKeeper session ID: %w","messagePattern":"decode ZooKeeper session ID: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/zookeeper_protocol.go","lineNumber":171,"sourceCode":"\trequest.int64(0)\n\trequest.bytes(make([]byte, 16))\n\tif err := client.writeFrame(request.data()); err != nil {\n\t\treturn nil, fmt.Errorf(\"send ZooKeeper connect request: %w\", err)\n\t}\n\tresponse, err := client.readFrame()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read ZooKeeper connect response: %w\", err)\n\t}\n\tdecoder := newZooKeeperDecoder(response)\n\tif _, err := decoder.int32(); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode ZooKeeper protocol version: %w\", err)\n\t}\n\tif _, err := decoder.int32(); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode ZooKeeper session timeout: %w\", err)\n\t}\n\tsessionID, err := decoder.int64()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"decode ZooKeeper session ID: %w\", err)\n\t}\n\tif _, err := decoder.bytes(); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode ZooKeeper session password: %w\", err)\n\t}\n\tif sessionID == 0 {\n\t\treturn nil, zk.ErrSessionExpired\n\t}\n\treturn client, nil\n}\n\nfunc zooKeeperTimeoutMillis(timeout time.Duration) int32 {\n\tmilliseconds := timeout.Milliseconds()\n\tif milliseconds < 1 {\n\t\treturn 1\n\t}\n\tif milliseconds > math.MaxInt32 {\n\t\treturn math.MaxInt32\n\t}","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/zookeeper_protocol.go#L153-L189","documentation":"The connect response carries the 64-bit session ID; if decoder.int64() fails (not enough bytes left in the frame), newProtocolZooKeeperClient returns this error. A successful decode of 0 leads to zk.ErrSessionExpired instead, so this error strictly means the bytes could not be read, not an invalid session.","triggerScenarios":"newProtocolZooKeeperClient decoding a connect response shorter than the layout through the session-ID field (~12 bytes missing/misplaced) — truncated or mis-framed server data.","commonSituations":"Proxy or firewall clipping large frames; test fakes with wrong byte counts (int32 vs int64 confusion); server sending an error payload instead of the normal ConnectResponse structure.","solutions":["Log/inspect the raw response frame and verify field sizes: int32 version, int32 timeout, int64 sessionID, bytes password","Fix any intermediary (proxy/NAT) that fragments or truncates the stream","Correct the encoder in test doubles to write the session ID as a full 8-byte int64","Upgrade/align ZooKeeper client and server versions to the same wire protocol"],"exampleFix":"// before (test fake)\nbuf.int32(0) // wrong: wrote sessionID as int32\n// after\nbuf.int32(0)\nbuf.int32(30000)\nbuf.int64(0x1234) // full 64-bit session ID\nbuf.bytes(passwd)","handlingStrategy":"type-guard","validationCode":"func frameHasSessionID(decoder *zooKeeperDecoder) bool {\n    return decoder.remaining() >= 8 // sessionID int64 after version+timeout\n}","typeGuard":null,"tryCatchPattern":"client, err := newProtocolZooKeeperClient(conn, timeout)\nif err != nil {\n    var expired = (err == zk.ErrSessionExpired) // note: sessionID==0 maps here, not this decode error\n    if !expired && strings.Contains(err.Error(), \"decode ZooKeeper session ID\") {\n        log.Error(\"connect response missing/truncated session ID\")\n    }\n    return err\n}","preventionTips":["Encode session IDs as full 8-byte values in fakes and tooling","Validate field sizes (int32/int32/int64/bytes) when hand-crafting frames","Compare against a wire capture from go-zk for layout correctness"],"tags":["zookeeper","protocol","decoding"],"backgroundTag":"protocol-decode-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}