{"record":{"id":"04423f72ac1f2a94","repo":"argoproj/argo-workflows","slug":"no-active-session","errorCode":null,"errorMessage":"no active session","messagePattern":"no active session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/sqldb/session.go","lineNumber":277,"sourceCode":"\n\treturn false\n}\n\n// With executes with a db Session\nfunc (sp *SessionProxy) With(ctx context.Context, fn func(db.Session) error) error {\n\tlogger := logging.RequireLoggerFromContext(ctx)\n\tsp.mu.RLock()\n\tif sp.closed {\n\t\tsp.mu.RUnlock()\n\t\tlogger.Warn(ctx, \"session proxy is closed\")\n\t\treturn fmt.Errorf(\"session proxy is closed\")\n\t}\n\n\tsess := sp.sess\n\tsp.mu.RUnlock()\n\n\tif sess == nil {\n\t\treturn fmt.Errorf(\"no active session\")\n\t}\n\n\terr := fn(sess)\n\tif err == nil {\n\t\treturn nil\n\t}\n\n\t// If it's not a network error or inside a tx do not retry\n\tif !sp.isNetworkError(err) || sp.insideTransaction {\n\t\treturn err\n\t}\n\n\tif reconnectErr := sp.reconnectIfStale(ctx, sess); reconnectErr != nil {\n\t\treturn fmt.Errorf(\"operation failed and reconnection failed: %w\", reconnectErr)\n\t}\n\n\tsp.mu.RLock()\n\tsess = sp.sess","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/util/sqldb/session.go#L259-L295","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the root DB connection failure (check persistence config: postgres/mysql host, port, credentials, secrets) — With will work once a session is established.","Call Reconnect(ctx) explicitly after fixing connectivity and check its error before issuing queries.","Verify NewPersistence/connect completed successfully at startup; fail fast instead of serving traffic with a sessionless proxy.","Wrap calls so this error triggers a delayed retry with backoff rather than failing the workflow operation permanently."],"exampleFix":"// before\noffload := sqldb.NewOfflineOffloadOrNumericIDRepo(...)\nerr := offload.Save(ctx, wf) // \"no active session\"\n// after\nproxy := sqldb.NewSessionProxy(...)\nif err := proxy.Reconnect(ctx); err != nil {\n\tlogger.Error(ctx, \"db reconnect failed\", err)\n\treturn err\n}\nerr := proxy.With(ctx, func(s db.Session) error { return save(s, wf) })","handlingStrategy":"retry","validationCode":"if proxy.Session() == nil {\n\tif err := proxy.Reconnect(ctx); err != nil {\n\t\treturn fmt.Errorf(\"database session unavailable: %w\", err)\n\t}\n}","typeGuard":"func hasActiveSession(sp *sqldb.SessionProxy) bool { return sp.Session() != nil }","tryCatchPattern":"err := proxy.With(ctx, fn)\nif err != nil && strings.Contains(err.Error(), \"no active session\") {\n\tif rerr := proxy.Reconnect(ctx); rerr == nil {\n\t\terr = proxy.With(ctx, fn)\n\t}\n}","preventionTips":["Fail fast at startup if the initial DB connect fails instead of serving with a sessionless proxy.","Validate persistence config before constructing the proxy.","Call Reconnect and check its error after any connectivity incident before issuing queries.","Monitor logs for repeated reconnection failures — sess stays nil until one succeeds."],"tags":["database","session-lifecycle","initialization"],"backgroundTag":"no-active-db-session","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}