-
Notifications
You must be signed in to change notification settings - Fork 1.9k
OAuthProxy: _refresh_locks dict grows unboundedly with token churn #3866
Copy link
Copy link
Open
Labels
authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Metadata
Metadata
Assignees
Labels
authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.Related to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Description
OAuthProxy._refresh_locks(line 559 ofproxy.py) creates ananyio.Lockperupstream_token_idto prevent concurrent refresh races. Entries are never removed, so the dict grows monotonically with every distinct token ID.Impact
Growth rate is one entry per unique user whose token has been refreshed. Each entry is ~200 bytes (lock object + string key). In a typical deployment this is bounded by the user base, so it's unlikely to cause issues unless the proxy runs for a very long time with high user churn.
Reproduction
Possible fixes
OrderedDict+ LRU eviction (simplest, minor race window on evicted entries)Found during an audit of unaddressed review feedback on merged PRs (originally flagged by Codex bot on PR #3713).