fix: run every statement on one connection of the plugin's pool (#543) #544

Merged
maximus merged 3 commits from issue-543-single-connection-pool into main 2026-11-14 01:18:44 +00:00

3 commits

Author SHA1 Message Date
le king fu
5f4ef5aeee test(db): pin the write lock held while the new pool opens (#543)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m16s
PR Check — Rust / rust (pull_request) Successful in 4m26s
The review of PR #544 (comment 33133) left one mutation green: read the
plugin's options under the read lock of DbInstances, open the new pool
without any lock, then take the write lock for the insert only. A
statement of the plugin (execute, select) arriving while the new pool
opens would then find the plugin's pool instead of waiting for the swap.

The new test polls the swap once, so that it waits in the opening of the
new pool, then looks the pool up as the plugin's execute does: it must
wait for the swap and find the pool of one connection.

Refs #543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 19:23:43 -05:00
le king fu
0f289460bb docs: ADR 0027 and the one-connection pool in the docs (#543)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m25s
PR Check — Rust / rust (pull_request) Successful in 15m50s
New ADR 0027: the pool switch, what it relies on in tauri-plugin-sql and
what a bump of the plugin, of its JS half or of sqlx re-checks. ADR 0021:
its section 7 (Journal lines of db.ts, the switch as the one step whose
failure fails the opening besides Database.load) and the startup delay.
docs/architecture.md: DB access, the db.ts row, 46 commands and the
db_pool_commands.rs section, the tauri-plugin-sql row, the ADR table.
CLAUDE.md: module tree and database access. REVIEW.md, outside the
"Niveaux" section: the switch in the "Migrations, profils et donnees"
zone, a "Dependances" rule for a bump, and the "Transaction hors verrou"
trap. STATE.md: the follow-up on the lock assuming one connection gives
way to the one this work found on a failed profile creation.

Refs #543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:35:01 -05:00
le king fu
ba48ecd356 fix(db): run every statement on one connection of the plugin's pool (#543)
tauri-plugin-sql opens each database with Pool::connect, a sqlx pool of
up to ten connections, and sqlx gives a connection back to its pool
through a spawned task. Two statements sent back to back made the pool
open a second connection and serve both in turn, so a transaction of
withTransaction was split: its BEGIN and first write on one connection,
a later write on the other, which waited for the first one's write lock
and failed with "database is locked" (code 5) after 5 s. Adding a keyword
from the right-click menu (six statements) and creating a sub-category
hit it; the 14 withTransaction call sites were exposed.

Right after Database.load, inside the exclusive section that opens a
profile, loadUnlocked now calls use_single_connection_pool, a new Tauri
command (db_pool_commands.rs) that replaces the plugin's DbPool::Sqlite
in DbInstances by a pool of one connection, never recycled, opened with
the plugin pool's own connect options, then closes the plugin's pool.
getDb() and withTransaction find the connection only once the switch
succeeded; a failed switch writes a folder-free Journal line, closes the
plugin's pool and fails the opening.

sqlx 0.8.6 becomes a direct dependency with features the plugin already
enables: Cargo.lock only gains the edge, no package.

test: reproduces #543. The Rust tests replay, on a real sqlx pool opened
like the plugin's, the statements of a keyword on one then two checked
transactions (one split) and of a sub-category: code 5 on the plugin's
pool, green after the swap (6 of 6 red on a no-op swap). db.test.ts pins
the place of the switch and its failure path.

Fixes #543

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 20:34:54 -05:00