{"record":{"id":"4469a882bacf8cfc","repo":"t8y2/dbx","slug":"zookeeper-request-failed-with-error-code-d","errorCode":null,"errorMessage":"ZooKeeper request failed with error code %d","messagePattern":"ZooKeeper request failed with error code (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/zookeeper_protocol.go","lineNumber":403,"sourceCode":"\nfunc zooKeeperError(code int32) error {\n\tswitch code {\n\tcase 0:\n\t\treturn nil\n\tcase -4:\n\t\treturn zk.ErrConnectionClosed\n\tcase -101:\n\t\treturn zk.ErrNoNode\n\tcase -102:\n\t\treturn zk.ErrNoAuth\n\tcase -112:\n\t\treturn zk.ErrSessionExpired\n\tcase -115:\n\t\treturn zk.ErrAuthFailed\n\tcase -124:\n\t\treturn errZooKeeperSessionClosedRequiresSASL\n\tdefault:\n\t\treturn fmt.Errorf(\"ZooKeeper request failed with error code %d\", code)\n\t}\n}\n\ntype zooKeeperEncoder struct {\n\tbuffer bytes.Buffer\n}\n\nfunc (encoder *zooKeeperEncoder) int32(value int32) {\n\tvar data [4]byte\n\tbinary.BigEndian.PutUint32(data[:], uint32(value))\n\tencoder.buffer.Write(data[:])\n}\n\nfunc (encoder *zooKeeperEncoder) int64(value int64) {\n\tvar data [8]byte\n\tbinary.BigEndian.PutUint64(data[:], uint64(value))\n\tencoder.buffer.Write(data[:])\n}","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/zookeeper_protocol.go#L385-L421","documentation":"The ZooKeeper server returned a non-zero error code (RC) in a response header, and the code is not one of the ones this driver maps to a specific sentinel (ConnectionClosed, NoNode, NoAuth, SessionExpired, AuthFailed, SASL-required). zooKeeperError wraps it as a generic error carrying the raw integer code so the caller can still see what the server said.","triggerScenarios":"Any request (Get/Set/Create/Delete/Children) where the server replies with an unmapped RC: e.g. -110 ConnectionLoss (connection dropped mid-request), -100 NodeExists when creating an existing node, -111 SessionMoved, -119 AuthFailed variants, or any future/new server error code this driver doesn't recognize.","commonSituations":"Hitting NodeExists (code -100) because Create is called without EPHEMERAL handling or after a retry re-ran a successful create; SessionMoved when two clients share one session (forked process or duplicated credentials); ConnectionLoss during network blips or GC pauses on the server; upgrading ZooKeeper servers to a version emitting codes this driver predates.","solutions":["Log the full error including the numeric code and look it up in the ZooKeeper documentation — the code identifies the exact server-side condition.","For code -100 (NodeExists), check existence first or add an exists-and-reconcile path around Create; for create-if-absent semantics retry the operation on -100.","For -110 (ConnectionLoss), make the operation idempotent and retry with backoff on a reconnected client.","For -111/-112 session issues, ensure only one client instance uses a given session (don't share chroot/credentials across processes) and re-create the client on session loss.","If the code is a valid server error not mapped by this driver, extend zooKeeperError's switch to map it to a sentinel."],"exampleFix":"// before\n_, _, err := zkClient.Create(path, data, 0, acl)\n\n// after\n_, _, err := zkClient.Create(path, data, zk.FlagEphemeral, acl)\nif err == zk.ErrNodeExists {\n    _, statErr := zkClient.Set(path, data, -1) // reconcile instead of failing\n    return statErr\n}\nreturn err","handlingStrategy":"try-catch","validationCode":"// pre-check for the most common code (-100 NodeExists)\nexists, _, err := zkClient.Exists(path)\nif err != nil {\n    return err\n}\nif exists && createOnce {\n    return nil // already created, nothing to do\n}","typeGuard":null,"tryCatchPattern":"_, _, err := client.request(payload)\nvar zkErr *zkError\nif errors.As(err, &zkErr) {\n    switch zkErr.code {\n    case -100: // NodeExists: reconcile\n    case -110, -111: // ConnectionLoss/SessionMoved: re-dial and retry idempotently\n    case -112: // SessionExpired: rebuild the client and session\n    default:\n        log.Errorf(\"zookeeper error code %d\", zkErr.code)\n    }\n}","preventionTips":["Log the raw numeric code — it maps 1:1 to a documented ZooKeeper condition.","Make writes idempotent (retries re-run operations; expect NodeExists).","Use ephemeral nodes + exists checks for create-once semantics.","Never share one ZooKeeper session/client between processes or instances."],"tags":["zookeeper","server-error","error-code","rpc"],"backgroundTag":"remote-server-error-code","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"}