OAuth non-rotating refresh: hold one DB connection per request (fix pool exhaustion)
Part of PLAN-017. Fixes the connection-ownership regression from Core PR #1246 that caused OAuth-refresh pool starvation (RCA Sept 24 2026). Full design: agent-plans PLAN-017.
Problem. OAuthTokenAPI.handleNonRotatingRefresh (:388, via
handleNonRotatingRefreshWithLock :354/:372) opens an outer
sqlStorage.startTransaction(con -> …, REPEATABLE_READ) (:398,
@UnauditedTransaction :387) and holds that connection for the whole
Hydra round-trip, while in-tx helpers borrow MORE connections from the same
3-max pool → hold-and-wait Hikari timeouts.
Cross-repo dependency (NOT auto-wired): needs the PLAN-017 pi contract
(isOAuthTokenRevokedByGID_Transaction) and pg impl merged/available.
What to change — thread con so no in-tx helper borrows a 2nd connection.
- Revocation read (always nested; 289 RCA events): the in-tx call to
OAuth.verifyAndUpdateIntrospectRefreshTokenPayload(...)(:419; defOAuth.java:460) →isTokenRevokedBasedOnPayload(OAuth.java:504) must use acon-aware overload callingoauthStorage.isOAuthTokenRevokedByGID_Transaction(appIdentifier, con, gid). Keep the existing non-conoverload for the rotating caller (:189). - Signing (cold-static + dynamic only; warm-static already DB-free via
PR #1413 at
SigningKeys.java:190-199— KEEP that fast path). Add acon-threaded path:OAuth.transformTokens(...)(:449; defOAuth.java:331) →OAuthToken.reSignToken(..., con)→SigningKeys.getStaticKeyForAlgorithm(algorithm, con)/getAllKeys(con)/getLatestIssuedDynamicKey(con). On a cache miss the signing-key read must rungetJWTSigningKeys_Transaction(appIdentifier, con)on the passed connection, neverJWTSigningKey.getOrCreateAndGetKeyForAlgorithm's ownstartTransaction(JWTSigningKey.java:194). PREFERRED: pre-warm the signing keys BEFOREstartTransactionso the in-tx path is read/cache only and no key is created inside the REPEATABLE_READ transaction. - Client lookup: if any client resolution happens inside the tx (e.g.
inside
OAuthProxyHelper.proxyFormPOSTcredential handling), route it throughconor hoist it beforestartTransaction. The handler already carries a loadedoauthClientparam — prefer reusing it and assert no storage lookup occurs in the callback. - Leave
updateLastActive(:464, def:315) OUT of the tx — it may hit a different tenant's pool; document this so nobody threads it in. - Keep the
@UnauditedTransactionannotations as-is (behaviour unchanged; full startAuditedTransaction conversion is PLAN-012 backlog).
Acceptance.
- A single non-rotating refresh performs exactly ONE pool acquisition for its whole DB lifetime (asserted by the PLAN-017 repro test).
- Warm-static-key fast path preserved (no DB on cache hit).
- Existing OAuth tests green; no behaviour change to responses.
- CHANGELOG line under the topmost unreleased section:
Fix: non-rotating OAuth refresh held multiple DB connections per request, causing pool exhaustion under load. - No version bump in the PR.
Depends-on: supertokens/supertokens-plugin-interface#223 Depends-on: supertokens/supertokens-postgresql-plugin#407 Plan: PLAN-017
Source: supertokens/supertokens-core