{"record":{"id":"35155a750c032ab9","repo":"t8y2/dbx","slug":"zookeeper-session-expired-during-connection-35155a","errorCode":null,"errorMessage":"ZooKeeper session expired during connection","messagePattern":"ZooKeeper session expired during connection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-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/hive-go/discovery.go#L194-L230","documentation":"The ZooKeeper session expired while the client was still establishing its connection (StateExpired event), so waitForZooKeeperSession aborts. The ensemble considered the client dead (e.g. no heartbeat within sessionTimeout) before a usable session was confirmed.","triggerScenarios":"Calling Endpoints when the ZooKeeper ensemble drops the ephemeral session during connect — network stalls, long GC pauses, or a sessionTimeout shorter than the connection latency to a distant quorum.","commonSituations":"Cross-region or high-latency links to ZooKeeper with a small session timeout, JVM/ZK ensemble restarts, client clock or network jitter causing missed heartbeats, tickTime too small on the ensemble.","solutions":["Increase the ZooKeeper session timeout to exceed network round-trip latency","Check network stability between client and ensemble (packet loss, MTU issues)","Verify ensemble tickTime/sessionTimeout configuration is adequate","Add retry/backoff around Endpoints so transient session expiry is retried"],"exampleFix":"// before\nzk.Connect(ctx, hosts, zk.WithSessionTimeout(2*time.Second)) // expires on WAN\n// after\nzk.Connect(ctx, hosts, zk.WithSessionTimeout(30*time.Second))","handlingStrategy":"retry","validationCode":"// ensure configured timeout comfortably exceeds measured RTT\nrtt := measureRTT(zkHost) // e.g. via TCP connect timing\nif sessionTimeout < 10*rtt {\n    return fmt.Errorf(\"session timeout %v too small for RTT %v\", sessionTimeout, rtt)\n}","typeGuard":null,"tryCatchPattern":"endpoints, err := discovery.Endpoints(ctx)\nif err != nil && strings.Contains(err.Error(), \"session expired\") {\n    // reconnect with a larger session timeout\n    return retryWithNewSession(ctx, 30*time.Second)\n}","preventionTips":["Set sessionTimeout well above network latency and GC pause ceilings","Avoid long stop-the-world pauses in the client process during connect","Add automatic reconnect/retry for transient session expiry"],"tags":["zookeeper","session","timeout","network"],"backgroundTag":"zookeeper-session-expired","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"}