In-memory storage: classify FK conflicts without borrowing a second connection
Part of PLAN-018, Unit 2 (core in-memory ONLY). Full design: agent-plans PLAN-018.
Problem. The in-memory isForeignKeyConstraintError
(src/main/java/io/supertokens/inmemorydb/Start.java:1807) runs a
verification SELECT via QueryExecutorTemplate.execute(this, …), which
borrows a NEW SQLite connection from the shared in-memory pool. It is
called from catch blocks inside _Transaction write methods
(addPermissionToRoleOrDoNothingIfExists_Transaction,
insertUsedCode_Transaction, and every other _Transaction write that
does FK-conflict handling) while the transaction connection is held —
tripping the nested-acquisition guard on every FK-conflict path.
Fix (either approach).
- PREFERRED: add a
con-taking form so the verificationSELECTruns on the transaction connection already held by the caller (QueryExecutorTemplate.execute(con, …)), and passconfrom the_Transactioncatch blocks; or - classify the constraint without issuing any query if the SQLite error text carries enough to identify the table/columns.
Behaviour must be unchanged — same true/false classification, same exception mapping.
Acceptance.
- No in-memory FK-conflict path borrows a second connection; the guard (warn-mode) logs nothing for these flows.
TOTPStorageTest,UserRolesStorageTest, and the EmailPassword / WebAuthn credential-insert sqlite tests pass with no nested-acquisition warning.- No CHANGELOG needed (in-memory test-storage internals; no public change).
Scope note: the postgres isForeignKeyConstraintError is already
connection-free (classifies from ServerErrorMessage) — do NOT change it.
Plan: PLAN-018
Source: supertokens/supertokens-core