fix(secrets): make concurrent SQLite store initialisation safe; bump to 0.6.4 (unpublished) (scadaproj#25)

Several setups migrating one SQLite secret store at once (mxaccessgw's parallel test hosts on the
per-process store) failed intermittently on Windows with "cannot start a transaction within a
transaction" from SqliteSecretsStoreMigrator.MigrateAsync. That message means the BEGIN ran on a
handle that was already in a transaction: the pinned Microsoft.Data.Sqlite 10.0.7 can hand one
pooled handle to two owners (dotnet/efcore#39009, fixed in 10.0.13) and no 10.0.x refuses to
re-pool a handle whose rollback failed (dotnet/efcore#39082).

The migrator now serialises migrations of one store per process behind a gate keyed on the
normalised path, runs each attempt on a dedicated unpooled connection inside BEGIN IMMEDIATE, and
retries SQLITE_BUSY/SQLITE_LOCKED (another process past the busy timeout) with equal-jitter
exponential backoff. Store operations and the Microsoft.Data.Sqlite pin are unchanged.

Tests: concurrent-init (16 hosts x 20 rounds on fresh and existing stores, two path spellings,
16 AddZbSecrets containers running the pre-host migrator + hosted service), gate sharing/waiting,
BUSY retry past the 5 s busy timeout, transient-code classification.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 13:57:53 -05:00
parent 01c6dc1d02
commit f21f2e551d
7 changed files with 420 additions and 9 deletions
+23
View File
@@ -5,6 +5,29 @@ follows [Keep a Changelog](https://keepachangelog.com/); versions are shared acr
package in the family (see `Directory.Build.props`) even when a given release only touches
one of them.
## 0.6.4 — unreleased (NOT published to the feed)
### Fixed
- **SQLite store initialisation is safe when several setups run at once on one store**
(scadaproj#25). mxaccessgw's parallel test hosts, each migrating the same per-process store,
failed intermittently on the Windows nightly with `SqliteException: cannot start a transaction
within a transaction` from `SqliteSecretsStoreMigrator.MigrateAsync`. The migrator now:
- serialises migrations of one store within a process behind a process-wide gate keyed on the
normalised store path (`Path.GetFullPath`; case-insensitive on Windows and macOS), however
many factories, migrators or DI containers point at it;
- runs each attempt on a dedicated **unpooled** connection inside `BEGIN IMMEDIATE`, so it can
neither be handed a pooled handle another owner is still using nor leave one behind in a
transaction. The pinned Microsoft.Data.Sqlite `10.0.7` can hand one pooled handle to two
owners (dotnet/efcore#39009, fixed in `10.0.13`), and no `10.0.x` refuses to re-pool a handle
whose rollback failed (dotnet/efcore#39082); both surface as exactly this error on the next
`BEGIN`;
- retries `SQLITE_BUSY` / `SQLITE_LOCKED` (another process holding the write lock past the 5 s
busy timeout) up to 6 attempts on a fresh connection with equal-jitter exponential backoff.
No schema, wire or configuration change; store operations other than the migration are unchanged.
The Microsoft.Data.Sqlite pin stays at `10.0.7` so this patch does not raise the consumer floor.
## 0.6.3 — 2026-09-28
### Added