{"record":{"id":"3d2c1aa9b8a464ad","repo":"t8y2/dbx","slug":"zookeeper-connection-event-w-3d2c1a","errorCode":null,"errorMessage":"ZooKeeper connection event: %w","messagePattern":"ZooKeeper connection event: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/discovery.go","lineNumber":204,"sourceCode":"\t}\n\treturn \"/\" + strings.Join(cleaned, \"/\")\n}\n\nfunc waitForZooKeeperSession(ctx context.Context, events <-chan zk.Event, timeout time.Duration) error {\n\ttimer := time.NewTimer(timeout)\n\tdefer timer.Stop()\n\tfor {\n\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","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/discovery.go#L186-L222","documentation":"While waiting for the ZooKeeper session to establish, the watch event channel delivered an event carrying a non-nil Err. The library wraps that underlying connection error with %w so the root cause (DNS failure, connection refused, TLS error, etc.) remains inspectable via errors.Is/As.","triggerScenarios":"waitForZooKeeperSession, called from Endpoints right after dialing, receives a zk.Event with Err set — i.e. the go-zk client reported a connection-level failure before reaching StateHasSession.","commonSituations":"ZooKeeper ensemble unreachable (firewall, wrong host list), TLS handshake failure against a SASL/SSL ensemble, ensemble quorum loss while connecting, or resolving to a dead server in the connection string.","solutions":["Unwrap with errors.Is/As to identify the underlying connection error and fix that cause first.","Verify the ZooKeeper connection string hosts/ports are reachable (nc/zkCli from the client host).","Increase the connect timeout if the ensemble is slow to establish sessions.","If the ensemble requires TLS or SASL, ensure the dialer and auth configuration match the server setup."],"exampleFix":"// before\nif err := waitForZooKeeperSession(ctx, events, timeout); err != nil {\n    return err\n}\n// after\nif err := waitForZooKeeperSession(ctx, events, timeout); err != nil {\n    var netErr net.Error\n    if errors.As(err, &netErr) { return fmt.Errorf(\"zk unreachable: %w\", err) }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Reachability pre-check before dialing\nconn, err := net.DialTimeout(\"tcp\", \"zk1:2181\", 3*time.Second)\nif err != nil { log.Fatal(\"ZooKeeper unreachable: \", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"if err := waitForZooKeeperSession(ctx, events, timeout); err != nil {\n    var transient interface{ Temporary() bool }\n    if errors.As(err, &transient) && transient.Temporary() {\n        return retryWithBackoff(ctx)\n    }\n    return fmt.Errorf(\"zk session setup failed: %w\", err)\n}","preventionTips":["Pre-flight network checks to ZooKeeper host/port","Size connect timeouts for ensemble latency","Match TLS/SASL client config to the ensemble","Monitor ZooKeeper quorum health"],"tags":["zookeeper","connection","network","timeout"],"backgroundTag":"zookeeper-connection-error","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"}