{"record":{"id":"8ab63bcc8ad26be4","repo":"t8y2/dbx","slug":"invalid-zookeeper-buffer-length-d-8ab63b","errorCode":null,"errorMessage":"invalid ZooKeeper buffer length %d","messagePattern":"invalid ZooKeeper buffer length (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/zookeeper_protocol.go","lineNumber":491,"sourceCode":"\nfunc (decoder *zooKeeperDecoder) int64() (int64, error) {\n\tvalue, err := decoder.take(8)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn int64(binary.BigEndian.Uint64(value)), nil\n}\n\nfunc (decoder *zooKeeperDecoder) bytes() ([]byte, error) {\n\tlength, err := decoder.int32()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif length == -1 {\n\t\treturn nil, nil\n\t}\n\tif length < -1 {\n\t\treturn nil, fmt.Errorf(\"invalid ZooKeeper buffer length %d\", length)\n\t}\n\tvalue, err := decoder.take(int(length))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn append([]byte(nil), value...), nil\n}\n\nfunc (decoder *zooKeeperDecoder) string() (string, error) {\n\tvalue, err := decoder.bytes()\n\treturn string(value), err\n}\n\nfunc (decoder *zooKeeperDecoder) strings() ([]string, error) {\n\tlength, err := decoder.int32()\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/zookeeper_protocol.go#L473-L509","documentation":"The ZooKeeper binary decoder's bytes() reads an int32 length prefix for a byte buffer. Per the protocol, -1 means a null buffer (returned as nil); any other negative length is invalid and triggers this error. It guards against corrupted streams where a bogus negative value would otherwise be used as an allocation size.","triggerScenarios":"Called from Get (getData), authenticateSASL, and the string()/test-serving paths whenever a decoded buffer length prefix is < -1 — i.e. the byte stream is misaligned or corrupted at that position.","commonSituations":"Reading a znode whose stored data is corrupted or was written by a non-conforming client, protocol desync after an earlier partial/failed read, a man-in-the-middle or truncated TLS stream, or pointing the client at something that isn't speaking the ZooKeeper binary protocol.","solutions":["Close and reopen the connection — once desynced, subsequent decodes will keep producing garbage.","Verify TLS is configured identically on client and server if the server requires it; a plaintext-vs-TLS mismatch garbles every frame.","Reproduce with a raw read (or readZooKeeperTestFrame) and hexdump the response to confirm the length prefix value and stream alignment.","Check the writer of the offending znode's data for corruption or a buggy custom serializer.","Upgrade the client/server pair to compatible ZooKeeper versions to rule out protocol incompatibility."],"exampleFix":"// before\nvalue, err := zkClient.Get(\"/cfg/node\") // previous failed read left stream desynced\n// after\nclient, err := hive.Dial(connStr) // reconnect on any decode error\nvalue, err := client.Get(\"/cfg/node\")","handlingStrategy":"retry","validationCode":"// ensure the data you wrote is well-formed before reading it back\nif len(payload) == 0 {\n\treturn errors.New(\"refusing to write empty payload to \" + path)\n}\nif _, err := client.Set(path, payload, -1); err != nil {\n\treturn fmt.Errorf(\"write znode: %w\", err)\n}","typeGuard":"func isInvalidBufferLength(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"invalid ZooKeeper buffer length\")\n}","tryCatchPattern":"value, err := client.Get(path)\nif err != nil {\n\tif isInvalidBufferLength(err) {\n\t\t// stream is desynced: rebuild the connection once, then retry\n\t\tclient.Close()\n\t\tclient, err = hive.Dial(connStr)\n\t\tif err == nil {\n\t\t\tvalue, err = client.Get(path)\n\t\t}\n\t}\n\tif err != nil {\n\t\treturn fmt.Errorf(\"zk get %s: %w\", path, err)\n\t}\n}","preventionTips":["Only write znode data through conforming clients; avoid custom serializers for stored payloads.","Treat any decode error as fatal for the connection and immediately reconnect.","Match TLS settings exactly on client and server to prevent garbled frames.","Validate data round-trips in CI by writing and reading back via the same library.","Monitor for this error as an early signal of a corrupted or truncated network path."],"tags":["zookeeper","protocol-decode","corrupt-data","stream-desync"],"backgroundTag":"invalid-decoder-length","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"}