Skip to content

chore(async): track fire-and-forget goroutines, drain on shutdown#696

Merged
lakhansamani merged 1 commit into
mainfrom
chore/graceful-shutdown-goroutines
Jul 22, 2026
Merged

chore(async): track fire-and-forget goroutines, drain on shutdown#696
lakhansamani merged 1 commit into
mainfrom
chore/graceful-shutdown-goroutines

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor

Why

Detached go func() calls on the request path (email/SMS send, webhook
events, audit log writes) were invisible to graceful shutdown and, if they
panicked, took down the entire process — not just the one request.

What

  • New internal/asyncutil package: Go(log, fn) tracks the goroutine and
    recovers any panic; Wait(log) blocks until all tracked goroutines finish.
  • Every fire-and-forget goroutine in internal/service/, internal/http_handlers/,
    and internal/audit/ now goes through asyncutil.Go instead of a bare go func().
  • internal/server/server.go calls asyncutil.Wait after the HTTP/metrics
    listeners stop, before the process exits.
  • Long-running loops already tied to ctx (listeners, ticker-based cache
    eviction) are untouched — they don't need draining.

Test plan

  • go build ./..., go vet ./...
  • internal/asyncutil unit tests (drain + panic-recovery)
  • TEST_DBS=sqlite go test -p 1 ./internal/... — full suite green

Every detached go func() on the request path (email/SMS send, webhook
events, audit log writes) now runs through internal/asyncutil.Go instead
of a bare goroutine:

- server.Run() waits for all of them to finish (asyncutil.Wait) after
  the HTTP/metrics listeners stop accepting, so a request's side effects
  aren't silently dropped mid-flight on shutdown.
- asyncutil.Go recovers any panic in the closure and logs it, since an
  unrecovered panic in a bare goroutine takes down the whole process,
  not just the one request.
@lakhansamani
lakhansamani merged commit ea19ed5 into main Jul 22, 2026
4 checks passed
pull Bot pushed a commit to bhardwajRahul/authorizer that referenced this pull request Jul 22, 2026
Added to README:
- WebAuthn / passkey login
- Enterprise SSO (SAML 2.0 IdP & SP, OIDC broker, verified domains, home realm discovery)
- SCIM 2.0 provisioning
- Multi-tenant / org-scoped admin
- Migration guides (planned)

Added to CHANGELOG [Unreleased]:
- Service accounts as FGA subjects (authorizerdev#665)
- SAML ACS CSRF exemption fix (authorizerdev#666)
- Trusted-issuer token review config (authorizerdev#667)
- Session revocation on password reset (authorizerdev#669, authorizerdev#673)
- Multi-tenant SSO phases (authorizerdev#672, authorizerdev#674, authorizerdev#675)
- OIDC discovery caching + Twitter PKCE fix (authorizerdev#668)
- WebAuthn passkey support (authorizerdev#671)
- Per-user TOTP lockout + hashed recovery codes (authorizerdev#670)
- Server-side user search + org membership (authorizerdev#678, authorizerdev#680)
- Per-method MFA availability signals (authorizerdev#681)
- Consolidated MFA redesign narrative (authorizerdev#682-686)
- SAML 2.0 IdP role (authorizerdev#691)
- OAuth 2.1 / MCP hardening (authorizerdev#693)
- SCIM group provisioning + FGA + SAML assertions (authorizerdev#694)
- Provider template parity (authorizerdev#695)
- Recent fixes (async tracking, AGENTS.md rules, security fixes, storage parity, error typing, panics, frontend fixes) (authorizerdev#696-702)
pull Bot pushed a commit to bhardwajRahul/authorizer that referenced this pull request Jul 22, 2026
The initial 2.4.0 changelog pass covered authorizerdev#698-authorizerdev#702 but missed authorizerdev#696
(asyncutil goroutine tracking + panic recovery) — a real reliability
improvement, not just internal tooling, worth calling out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant