{"record":{"id":"3fc2df253b003832","repo":"t8y2/dbx","slug":"not-connected-3fc2df","errorCode":null,"errorMessage":"not connected","messagePattern":"not connected","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/main.go","lineNumber":598,"sourceCode":"\t}\n\terr := s.db.Close()\n\ts.db = nil\n\treturn err\n}\n\nfunc (s *server) validateConnection() error {\n\tdb, err := s.requireDB()\n\tif err != nil {\n\t\treturn err\n\t}\n\tctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\n\tdefer cancel()\n\treturn db.PingContext(ctx)\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":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/main.go#L580-L616","documentation":"requireDB returns this error when the server struct's db handle is nil, i.e. no successful connect/open has happened yet (or the connection was closed). Operations that need a database handle call requireDB first and fail fast with this message.","triggerScenarios":"Invoking any server RPC that needs the database (query, transaction, metadata, etc.) before a successful 'connect', or after close/disconnect left s.db nil.","commonSituations":"Application skipped the connect step due to earlier failed startup (e.g. the kingbase connection failed error); connection was closed by another goroutine; lifecycle ordering bug where work starts before initialization completes.","solutions":["Call 'connect' successfully before issuing any database operations and check its error","Track connection lifecycle so RPCs are only dispatched while connected; reconnect on demand","Guard application startup: abort or retry the connect step instead of proceeding to queries"],"exampleFix":"// before\nrows, err := s.query(params) // \"not connected\"\n// after\nif err := s.connect(cp); err != nil { return err } // establish first\nrows, err := s.query(params)","handlingStrategy":"validation","validationCode":"if s.db == nil { return errors.New(\"call connect before issuing database operations\") }","typeGuard":null,"tryCatchPattern":"db, err := s.requireDB(); if err != nil { /* reconnect then retry the operation once */ }","preventionTips":["Enforce lifecycle ordering: connect must succeed before any query/transaction RPC","Handle close/disconnect events by marking the server unavailable until reconnect","Add a health-check/test_connection call in startup before dispatching real work"],"tags":["connection","lifecycle","state"],"backgroundTag":"not-connected","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}