t8y2/dbx · error

not connected

Error message

not connected

What it means

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.

Source

Thrown at agents/drivers/kingbase-go/main.go:598

	}
	err := s.db.Close()
	s.db = nil
	return err
}

func (s *server) validateConnection() error {
	db, err := s.requireDB()
	if err != nil {
		return err
	}
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	return db.PingContext(ctx)
}

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 'connect' successfully before issuing any database operations and check its error
  2. Track connection lifecycle so RPCs are only dispatched while connected; reconnect on demand
  3. Guard application startup: abort or retry the connect step instead of proceeding to queries

Example fix

// before
rows, err := s.query(params) // "not connected"
// after
if err := s.connect(cp); err != nil { return err } // establish first
rows, err := s.query(params)
Defensive patterns

Strategy: validation

Validate before calling

if s.db == nil { return errors.New("call connect before issuing database operations") }

Try / catch

db, err := s.requireDB(); if err != nil { /* reconnect then retry the operation once */ }

Prevention

When it happens

Trigger: Invoking any server RPC that needs the database (query, transaction, metadata, etc.) before a successful 'connect', or after close/disconnect left s.db nil.

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

Related errors


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