feat: test-only guard against nested same-pool connection acquisition - #411
Draft
tamassoltesz wants to merge 3 commits into
Draft
tamassoltesz wants to merge 3 commits into
tamassoltesz wants to merge 3 commits into
Conversation
A call chain that holds one pooled connection (inside a startTransaction) and then borrows a SECOND from the same pool causes hold-and-wait pool exhaustion — the deadlock class behind the OAuth non-rotating-refresh regression and the WebAuthN.updateUserEmail issue. Both reached the second connection through helper indirection, which static analysis (ArchUnit) can't catch without flooding false positives; a runtime tripwire at the point of acquisition is precise instead. Track, per thread and per pool, that a startTransaction is in progress (marked after the transaction takes its own connection, so its own borrow isn't flagged), and reject a new same-pool borrow while that mark is set. Keyed per pool, so a cross-tenant borrow (different pool) is allowed; BulkImportProxyStorage is exempt (it reuses its transaction connection, never reaching getNewConnection). Active only under Start.isTesting — a no-op in production. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dEv4WZTfLTkphYkQXTqPj
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dEv4WZTfLTkphYkQXTqPj
Mirror of the core change: warn (stderr, with the borrowing call site) by default so the suite stays green while the pre-existing nested-acquisition instances are cleaned up (PLAN-018); an opt-in throwOnNestedAcquisition flag fails fast. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dEv4WZTfLTkphYkQXTqPj
Collaborator
Author
|
Updated: the guard now warns by default (opt-in throw), mirroring the core change (PR #1461) — PLAN-018 Unit 1. Merges green now; default flips to throw after the cleanup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A call chain that holds one pooled connection (inside a
startTransaction) and then borrows a second from the same pool causes hold-and-wait pool exhaustion — the deadlock class behind the OAuth non-rotating-refresh regression andWebAuthN.updateUserEmail. Both reached the second connection through helper indirection, which a static (ArchUnit) rule can't catch without flooding false positives. A runtime tripwire at the point of acquisition is precise instead.What
Track, per thread and per pool, that a
startTransactionis in progress — marked instartTransactionHelperafter the transaction takes its own connection, so its own borrow isn't flagged — and reject a new same-pool borrow while that mark is set (ConnectionPool.getConnection). It catches nested queries and nestedstartTransactions through any depth of helper indirection.updateLastActive) is allowed.BulkImportProxyStorageis naturally exempt — it reuses its transaction connection and never reachesgetNewConnection.Start.isTesting— a no-op in production (zero overhead).Pairing
Companion PR in supertokens-core (→
12.3) mirrors the guard in the in-memoryConnectionPooland adds the regression test. Draft: full-suite CI is the authoritative run — the guard is a tripwire and may surface additional un-audited instances (that's it working); known ones are OAuth (being fixed) and WebAuthn (fixed). Verified locally: full clean multi-repo compile passes.🤖 Generated with Claude Code
https://claude.ai/code/session_013dEv4WZTfLTkphYkQXTqPj