argoproj/argo-workflows · error

no active session

Error message

no active session

What it means

SessionProxy.With found sp.sess == nil: the proxy was constructed (or reset after a failed reconnect) without ever holding an open database session. Without a session it cannot execute fn, so it returns this error instead of a nil-pointer panic.

Source

Thrown at util/sqldb/session.go:277

	return false
}

// With executes with a db Session
func (sp *SessionProxy) With(ctx context.Context, fn func(db.Session) error) error {
	logger := logging.RequireLoggerFromContext(ctx)
	sp.mu.RLock()
	if sp.closed {
		sp.mu.RUnlock()
		logger.Warn(ctx, "session proxy is closed")
		return fmt.Errorf("session proxy is closed")
	}

	sess := sp.sess
	sp.mu.RUnlock()

	if sess == nil {
		return fmt.Errorf("no active session")
	}

	err := fn(sess)
	if err == nil {
		return nil
	}

	// If it's not a network error or inside a tx do not retry
	if !sp.isNetworkError(err) || sp.insideTransaction {
		return err
	}

	if reconnectErr := sp.reconnectIfStale(ctx, sess); reconnectErr != nil {
		return fmt.Errorf("operation failed and reconnection failed: %w", reconnectErr)
	}

	sp.mu.RLock()
	sess = sp.sess

View on GitHub (pinned to 35bff19146)

Solutions

  1. Fix the root DB connection failure (check persistence config: postgres/mysql host, port, credentials, secrets) — With will work once a session is established.
  2. Call Reconnect(ctx) explicitly after fixing connectivity and check its error before issuing queries.
  3. Verify NewPersistence/connect completed successfully at startup; fail fast instead of serving traffic with a sessionless proxy.
  4. Wrap calls so this error triggers a delayed retry with backoff rather than failing the workflow operation permanently.

Example fix

// before
offload := sqldb.NewOfflineOffloadOrNumericIDRepo(...)
err := offload.Save(ctx, wf) // "no active session"
// after
proxy := sqldb.NewSessionProxy(...)
if err := proxy.Reconnect(ctx); err != nil {
	logger.Error(ctx, "db reconnect failed", err)
	return err
}
err := proxy.With(ctx, func(s db.Session) error { return save(s, wf) })
Defensive patterns

Strategy: retry

Validate before calling

if proxy.Session() == nil {
	if err := proxy.Reconnect(ctx); err != nil {
		return fmt.Errorf("database session unavailable: %w", err)
	}
}

Type guard

func hasActiveSession(sp *sqldb.SessionProxy) bool { return sp.Session() != nil }

Try / catch

err := proxy.With(ctx, fn)
if err != nil && strings.Contains(err.Error(), "no active session") {
	if rerr := proxy.Reconnect(ctx); rerr == nil {
		err = proxy.With(ctx, fn)
	}
}

Prevention

When it happens

Trigger: Calling With (directly or via Save/Get/List/ListOldOffloads/ListWorkflowsLabelKeys/ListWorkflowsLabelValues) before the initial connect() succeeded, or after a reconnect attempt left sp.sess nil because connect() kept failing.

Common situations: Misconfigured persistence (bad credentials/host) at startup so the initial session never opens but the proxy object still exists; reconnectLocked failing on every retry leaving sess nil; races during proxy initialization.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/04423f72ac1f2a94. Report an issue: GitHub.