{"record":{"id":"fe86a0ec812d4fe9","repo":"t8y2/dbx","slug":"zookeeper-session-expired-during-connection","errorCode":null,"errorMessage":"ZooKeeper session expired during connection","messagePattern":"ZooKeeper session expired during connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/discovery.go","lineNumber":212,"sourceCode":"\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tcase <-timer.C:\n\t\t\treturn errors.New(\"ZooKeeper connection timed out before a session was established\")\n\t\tcase event, ok := <-events:\n\t\t\tif !ok {\n\t\t\t\treturn errors.New(\"ZooKeeper event stream closed before a session was established\")\n\t\t\t}\n\t\t\tif event.Err != nil {\n\t\t\t\treturn fmt.Errorf(\"ZooKeeper connection event: %w\", event.Err)\n\t\t\t}\n\t\t\tswitch event.State {\n\t\t\tcase zk.StateHasSession:\n\t\t\t\treturn nil\n\t\t\tcase zk.StateAuthFailed:\n\t\t\t\treturn errors.New(\"ZooKeeper authentication failed\")\n\t\t\tcase zk.StateExpired:\n\t\t\t\treturn errors.New(\"ZooKeeper session expired during connection\")\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc parseHiveServerRegistration(child string, data []byte) (endpoint, error) {\n\tcandidates := []string{strings.TrimSpace(string(data)), strings.TrimSpace(child)}\n\tfor _, candidate := range candidates {\n\t\tif candidate == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif value, err := endpointFromRegistrationJSON(candidate); err == nil {\n\t\t\treturn value, nil\n\t\t}\n\t\tparameters := parseHiveParameters(candidate)\n\t\tfor _, key := range []string{\"serveruri\", \"hiveserver2uri\", \"server_uri\"} {\n\t\t\tif raw := parameter(parameters, key); raw != \"\" {\n\t\t\t\treturn parseRegisteredEndpoint(raw)","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/discovery.go#L194-L230","documentation":"The ZooKeeper client reported StateExpired during the connection handshake, meaning the session that was being established expired before it became usable. This is terminal for this connection attempt; the caller must reconnect with a new session.","triggerScenarios":"waitForZooKeeperSession receives an event with event.State == zk.StateExpired while Endpoints() is establishing the connection, e.g. long GC pauses, network partitions, or an overloaded quorum delaying the handshake past the negotiated session timeout.","commonSituations":"Very short negotiated session timeouts; ZooKeeper quorum under load; network instability between driver and ensemble; process pauses (GC/VM suspend) exceeding the session timeout.","solutions":["Retry discovery to establish a fresh session","Increase the ZooKeeper session timeout in the client config","Fix network stability/quorum health (check server logs, ensemble latency) before retrying"],"exampleFix":"// before\nzk.Connect(hosts, zk.WithSessionTimeout(2*time.Second))\n// after\nzk.Connect(hosts, zk.WithSessionTimeout(30*time.Second))","handlingStrategy":"retry","validationCode":"// prefer generous session timeouts\nif cfg.ZKSessionTimeout < 10*time.Second {\n\tcfg.ZKSessionTimeout = 30 * time.Second\n}","typeGuard":null,"tryCatchPattern":"endpoints, err := discovery.Endpoints(ctx)\nif err != nil {\n\tif strings.Contains(err.Error(), \"session expired\") {\n\t\t// transient: rebuild connection and retry with backoff\n\t\tbackoff(retry)\n\t}\n}","preventionTips":["Set a session timeout comfortably above GC pause and network RTT expectations","Monitor ensemble load; expired sessions spike when quorums are saturated","Implement reconnect-with-backoff for session-expiry as a routine recovery path"],"tags":["zookeeper","session-expired","network"],"backgroundTag":"session-expired","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}