{"record":{"id":"2129773b68610804","repo":"t8y2/dbx","slug":"not-connected-212977","errorCode":null,"errorMessage":"Not connected","messagePattern":"Not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/zookeeper/connection.go","lineNumber":537,"sourceCode":"\nfunc millisecondsOrDefault(value int, fallback time.Duration) time.Duration {\n\tif value <= 0 {\n\t\treturn fallback\n\t}\n\treturn time.Duration(value) * time.Millisecond\n}\n\nfunc configuredStatLookupConcurrency(value string) int {\n\tparsed, err := strconv.Atoi(strings.TrimSpace(value))\n\tif err != nil {\n\t\treturn defaultStatLookupWorkers\n\t}\n\treturn maxInt(minimumStatLookupWorkers, minInt(maximumStatLookupWorkers, parsed))\n}\n\nfunc (service *server) requireClient() (znodeClient, error) {\n\tif service.activeClient == nil {\n\t\treturn nil, errors.New(\"Not connected\")\n\t}\n\treturn service.activeClient, nil\n}\n\nfunc (service *server) closeClient() {\n\tif service.activeClient != nil {\n\t\tservice.activeClient.Close()\n\t\tservice.activeClient = nil\n\t}\n\tservice.activeConfig = connectionConfig{}\n}\n\nfunc (session *clientSession) Close() {\n\tif session != nil && session.connection != nil {\n\t\tsession.connection.Close()\n\t}\n}\n","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/zookeeper/connection.go#L519-L555","documentation":"server.requireClient returns the currently active ZooKeeper session, and 'Not connected' when service.activeClient is nil. Operations (get, put, delete, listPrefix, connectionInfo) call it first, so any operation issued before openClient succeeds or after the client was closed yields this error.","triggerScenarios":"Calling dispatch operations (get/put/delete/listPrefix/connectionInfo) before a successful connect, after closeClient ran (connection closed or failed and was torn down), or after a connection attempt returned an error leaving activeClient nil. Raised in agents/drivers/zookeeper/connection.go:537.","commonSituations":"Using the driver without calling connect/openClient first; the ZooKeeper connection dropped and the driver closed the active client, then a request arrived; app startup ordering issuing KV operations before the connector finishes init; a failed reconnect leaving the server struct without a client.","solutions":["Call connect (openClient) and confirm it returns successfully before issuing any get/put/delete/list operations.","Reconnect after a failure: catch connection errors and re-run connect to repopulate activeClient before retrying the operation.","Check lifecycle ordering in your app so the driver's connect completes (or blocks) before workers start issuing operations.","Inspect logs for the earlier error that closed the client (timeout, auth failure) — this error is a symptom of that."],"exampleFix":"// before\nval, err := driver.Get(ctx, \"/foo\") // activeClient nil -> Not connected\n// after\nif err := driver.Connect(ctx, cfg); err != nil { return err }\nval, err := driver.Get(ctx, \"/foo\")","handlingStrategy":"try-catch","validationCode":"// Ensure the driver is connected before operations\nif driver.ActiveClient() == nil {\n    if err := driver.Connect(ctx, cfg); err != nil {\n        return fmt.Errorf(\"cannot connect to zookeeper before operation: %w\", err)\n    }\n}","typeGuard":"func connected(d *Server) bool { return d.ActiveClient() != nil }\n// usage: if !connected(driver) { reconnect first }","tryCatchPattern":"val, err := driver.Get(ctx, key)\nif err != nil && strings.Contains(err.Error(), \"Not connected\") {\n    if cerr := driver.Connect(ctx, cfg); cerr != nil { return cerr }\n    val, err = driver.Get(ctx, key) // retry once after reconnect\n}","preventionTips":["Sequence app startup: connect before any KV operations","Implement an auto-reconnect wrapper around all operations","Log and alert on the underlying error that closed the client","Add a readiness probe that requires an active ZooKeeper session"],"tags":["state","zookeeper","connection","lifecycle"],"backgroundTag":"not-connected","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"}