[Secrets] SQLite store initialisation/migration not safe under concurrent setup on one store (Windows) #25
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
mxaccessgw#150 traced an intermittent Windows CI failure — SQLite "cannot start a transaction within a transaction" (mxaccessgw nightly #143, run 817) — to two test classes initialising the same per-process ZB.MOM.WW.Secrets SQLite store concurrently. mxaccessgw worked around it by giving each test host its own store, but the library's SQLite store setup/migration is not safe when several initialisations on one store run at once (not reproduced on macOS: 0/480 concurrent setups — likely Windows file-locking specific).
Make store initialisation/migration concurrency-safe (process-wide per-path lock and/or BEGIN IMMEDIATE + retry on SQLITE_BUSY) and add a concurrent-init test; run it on windev too.
Fixed on main
f21f2e5(Secrets 0.6.4, not yet published). Not reproduced on windev (13 runs / ~4,000 concurrent setups on the old code, plus a 960k-open pool hammer), so the fix targets the most likely cause: Microsoft.Data.Sqlite 10.0.7's pool can hand one handle to two users (dotnet/efcore#39009, fixed in 10.0.13) and no 10.0.x refuses to re-pool a handle whose rollback failed mid-transaction (efcore#39082) — both produce exactly 'cannot start a transaction within a transaction'. Changes: migrations of one store serialise on a process-wide gate keyed by Path.GetFullPath; each attempt uses its own unpooled connection inside BEGIN IMMEDIATE; SQLITE_BUSY/LOCKED after the 5 s busy timeout retries ≤6× with jittered backoff. Other store operations and the Sqlite pin unchanged. Tests: 16 hosts × 20 rounds fresh/existing, two path spellings, 16 AddZbSecrets containers (mxgw pattern), gate sharing/waiting, retry past the busy timeout, retryable codes. Evidence: Mac Secrets solution 524 passed / 17 skipped / 0 failed (re-run green after rebase); windev concurrent-init tests 10/10 runs. The concurrency tests also passed on the old code (regression guard, not proof). App-wide Sqlite ≥ 10.0.13 and pre-existing Windows test failures filed separately.