Skip to content

Release per-issuer JWKS refresh workers on auth-server shutdown #6482

Closed

Description

@tgrunnagle

Summary

MultiIssuerTokenValidator starts one jwk.Cache per configured trusted issuer, each with its own httprc worker pool rooted at context.Background() (pkg/authserver/server/tokenexchange/multi_issuer_validator.go). The in-file comment is explicit that these run "for the life of the process" and to "budget roughly three goroutines per issuer".

Nothing releases them. Neither authserver.Server.Close() nor the new Server.CloseIdleConnections() reaches the validator, and jwk.Cache.Shutdown is never called.

Why this matters

This is the goroutine half of #6479. That issue's failure mode is a long-lived process that reconstructs the auth server to change its upstream set. #6480 fixed the HTTP-connection half — upstream pools are now bounded and drainable — but a reconstruction still leaks one worker pool per trusted issuer, unbounded.

It also reopens the pathological retry case for this resource specifically: buildProvider runs after buildUpstreams, so a reconstruction that fails past the upstream stage abandons the whole validator, and newServer's deferred drain covers only upstreams.

The gap is currently documented in the Scope: paragraph on Server.CloseIdleConnections; this issue is what that paragraph should eventually point at.

Suggested approach

  • Give MultiIssuerTokenValidator a Close/Shutdown that shuts down each per-issuer jwk.Cache.
  • Root the caches in a server-scoped context rather than context.Background().
  • Hold the validator on server and call it from both Close() and newServer's deferred error path.

Note pkg/auth/token.go's TokenValidator has the same shape, per the existing comment, so the fix may want to cover both.

Context

Metadata

Metadata

Assignees

Labels

needs-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions