t8y2/dbx · error

not connected

Error message

not connected

What it means

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'.

Source

Thrown at agents/drivers/xugu/main.go:1379

		s.ownsCancelDB = false
		s.nodeID = 0
		s.databaseSessionID = 0
		s.killSession = nil
		return nil
	}
	err := s.db.Close()
	s.db = nil
	s.cancelDB = nil
	s.ownsCancelDB = false
	s.nodeID = 0
	s.databaseSessionID = 0
	s.killSession = nil
	return err
}

func (s *server) validateConnection() error {
	if s.db == nil {
		return errors.New("not connected")
	}
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	return s.db.PingContext(ctx)
}

func openDB(params connectParams) (*sql.DB, error) {
	dsn := buildDSN(params)
	db, err := sql.Open("xugu", dsn)
	if err != nil {
		return nil, err
	}
	// One logical Agent session must map to exactly one server-side session so
	// schema, transaction, cursor, and cancellation state stay deterministic.
	db.SetMaxOpenConns(1)
	db.SetMaxIdleConns(1)
	db.SetConnMaxLifetime(30 * time.Minute)
	return db, nil

View on GitHub (pinned to c0390bff16)

Solutions

  1. Establish the connection (connect RPC) before validating
  2. Reconnect if the previous connection was closed or the agent restarted
  3. Retry after connect completes rather than during it

Example fix

// before
err := agent.TestConnection(ctx) // not connected
// after
if err := agent.Connect(ctx, cp); err != nil { return err }
err := agent.TestConnection(ctx)
Defensive patterns

Strategy: validation

Validate before calling

if !agent.Ready() { return errors.New("agent has no DB connection yet") }

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: 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).

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

Related errors


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