t8y2/dbx · error

not connected

Error message

not connected

What it means

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.

Source

Thrown at agents/drivers/vastbase-go/main.go:635

func (s *server) validateConnection() error {
	db, err := s.metadataDatabase()
	if err != nil {
		return err
	}
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	for attempt := 0; attempt < 2; attempt++ {
		err = db.PingContext(ctx)
		if !errors.Is(err, driver.ErrBadConn) {
			return err
		}
	}
	return err
}

func (s *server) requireDB() (*sql.DB, error) {
	if s.db == nil {
		return nil, errors.New("not connected")
	}
	return s.db, nil
}

func (s *server) beginOperation(timeoutSecs int) (context.Context, context.CancelFunc) {
	ctx := context.Background()
	var cancel context.CancelFunc
	if timeoutSecs > 0 {
		ctx, cancel = context.WithTimeout(ctx, time.Duration(timeoutSecs)*time.Second)
	} else {
		ctx, cancel = context.WithCancel(ctx)
	}
	s.activeCancelMu.Lock()
	s.activeCancel = cancel
	s.activeCancelMu.Unlock()
	return ctx, cancel
}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Call the connect RPC (and confirm ok) before issuing any metadata/query/DDL RPCs
  2. If the agent was restarted, re-open the session and reconnect instead of reusing the old session ID
  3. Serialize client operations so disconnect cannot race an in-flight request

Example fix

// before
rows, err := agent.Query(ctx, params) // may fail: not connected
// after
if err := agent.Connect(ctx, connectParams); err != nil { return err }
rows, err := agent.Query(ctx, params)
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: check agent reports a live connection before calling
if !agent.IsConnected() { return errors.New("connect first") }

Type guard

func isConnected(s *server) bool { return s != nil && s.db != nil }

Try / catch

res, err := agent.Query(ctx, p)
if err != nil && strings.Contains(err.Error(), "not connected") {
    if cerr := agent.Connect(ctx, cp); cerr != nil { return cerr }
    res, err = agent.Query(ctx, p)
}

Prevention

When it happens

Trigger: Calling any RPC that routes through requireDB() (metadata, query, DDL, etc.) without first calling connect, or after disconnect/close cleared s.db.

Common situations: 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.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/3c07fe286c809052. Report an issue: GitHub.