{"record":{"id":"1b8a381ffc8e5c50","repo":"t8y2/dbx","slug":"not-connected-1b8a38","errorCode":null,"errorMessage":"not connected","messagePattern":"not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/xugu/main.go","lineNumber":1379,"sourceCode":"\t\ts.ownsCancelDB = false\n\t\ts.nodeID = 0\n\t\ts.databaseSessionID = 0\n\t\ts.killSession = nil\n\t\treturn nil\n\t}\n\terr := s.db.Close()\n\ts.db = nil\n\ts.cancelDB = nil\n\ts.ownsCancelDB = false\n\ts.nodeID = 0\n\ts.databaseSessionID = 0\n\ts.killSession = nil\n\treturn err\n}\n\nfunc (s *server) validateConnection() error {\n\tif s.db == nil {\n\t\treturn errors.New(\"not connected\")\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\tdefer cancel()\n\treturn s.db.PingContext(ctx)\n}\n\nfunc openDB(params connectParams) (*sql.DB, error) {\n\tdsn := buildDSN(params)\n\tdb, err := sql.Open(\"xugu\", dsn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t// One logical Agent session must map to exactly one server-side session so\n\t// schema, transaction, cursor, and cancellation state stay deterministic.\n\tdb.SetMaxOpenConns(1)\n\tdb.SetMaxIdleConns(1)\n\tdb.SetConnMaxLifetime(30 * time.Minute)\n\treturn db, nil","sourceCodeStart":1361,"sourceCodeEnd":1397,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/xugu/main.go#L1361-L1397","documentation":"validateConnection on the xugu agent returns this when s.db is nil, i.e. no database connection has been established. Unlike requireDB's message, this variant also pings with a 5s timeout once a handle exists, so this error strictly means 'no handle at all'.","triggerScenarios":"Calling validateConnection (or RPCs that use it as a preflight) before connect, or after disconnect/killSession cleared s.db (note s.killSession = nil teardown path).","commonSituations":"Health-check pings fired while the agent is still connecting; using an old session handle after the agent restarted; a disconnect RPC completing just before a validation call.","solutions":["Establish the connection (connect RPC) before validating","Reconnect if the previous connection was closed or the agent restarted","Retry after connect completes rather than during it"],"exampleFix":"// before\nerr := agent.TestConnection(ctx) // not connected\n// after\nif err := agent.Connect(ctx, cp); err != nil { return err }\nerr := agent.TestConnection(ctx)","handlingStrategy":"validation","validationCode":"if !agent.Ready() { return errors.New(\"agent has no DB connection yet\") }","typeGuard":"func canValidate(s *server) bool { return s.db != nil }","tryCatchPattern":"err := agent.TestConnection(ctx)\nif err != nil && err.Error() == \"not connected\" {\n    if cerr := agent.Connect(ctx, cp); cerr != nil { return cerr }\n    err = agent.TestConnection(ctx)\n}","preventionTips":["Gate health checks on connection state","Avoid pinging during connect/disconnect transitions","Reconnect after agent restarts before validating"],"tags":["connection-state","health-check","guard"],"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"}