{"record":{"id":"3c07fe286c809052","repo":"t8y2/dbx","slug":"not-connected-3c07fe","errorCode":null,"errorMessage":"not connected","messagePattern":"not connected","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/vastbase-go/main.go","lineNumber":635,"sourceCode":"func (s *server) validateConnection() error {\n\tdb, err := s.metadataDatabase()\n\tif err != nil {\n\t\treturn err\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\n\tdefer cancel()\n\tfor attempt := 0; attempt < 2; attempt++ {\n\t\terr = db.PingContext(ctx)\n\t\tif !errors.Is(err, driver.ErrBadConn) {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn err\n}\n\nfunc (s *server) requireDB() (*sql.DB, error) {\n\tif s.db == nil {\n\t\treturn nil, errors.New(\"not connected\")\n\t}\n\treturn s.db, nil\n}\n\nfunc (s *server) beginOperation(timeoutSecs int) (context.Context, context.CancelFunc) {\n\tctx := context.Background()\n\tvar cancel context.CancelFunc\n\tif timeoutSecs > 0 {\n\t\tctx, cancel = context.WithTimeout(ctx, time.Duration(timeoutSecs)*time.Second)\n\t} else {\n\t\tctx, cancel = context.WithCancel(ctx)\n\t}\n\ts.activeCancelMu.Lock()\n\ts.activeCancel = cancel\n\ts.activeCancelMu.Unlock()\n\treturn ctx, cancel\n}\n","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/vastbase-go/main.go#L617-L653","documentation":"The vastbase-go agent's requireDB() guard returns this error when the server struct has no open *sql.DB handle (s.db == nil). It means an RPC requiring a live database connection was invoked before a successful connect, or after the connection was closed/reset. It is a state-guard error, not a network failure.","triggerScenarios":"Calling any RPC that routes through requireDB() (metadata, query, DDL, etc.) without first calling connect, or after disconnect/close cleared s.db.","commonSituations":"A client session skips the connect handshake (e.g. reusing a stale session ID after agent restart); the agent process restarted and in-memory state was lost; a disconnect RPC ran before a queued metadata/query RPC.","solutions":["Call the connect RPC (and confirm ok) before issuing any metadata/query/DDL RPCs","If the agent was restarted, re-open the session and reconnect instead of reusing the old session ID","Serialize client operations so disconnect cannot race an in-flight request"],"exampleFix":"// before\nrows, err := agent.Query(ctx, params) // may fail: not connected\n// after\nif err := agent.Connect(ctx, connectParams); err != nil { return err }\nrows, err := agent.Query(ctx, params)","handlingStrategy":"try-catch","validationCode":"// Go: check agent reports a live connection before calling\nif !agent.IsConnected() { return errors.New(\"connect first\") }","typeGuard":"func isConnected(s *server) bool { return s != nil && s.db != nil }","tryCatchPattern":"res, err := agent.Query(ctx, p)\nif err != nil && strings.Contains(err.Error(), \"not connected\") {\n    if cerr := agent.Connect(ctx, cp); cerr != nil { return cerr }\n    res, err = agent.Query(ctx, p)\n}","preventionTips":["Always complete the connect handshake before metadata/query RPCs","Reconnect after agent restarts instead of reusing stale sessions","Track connection lifecycle events in the client wrapper"],"tags":["connection-state","database","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"}