The deploy compose's SERIALIZABLE transaction range-locked every config table for the whole validate+compose+gzip: a concurrent edit held the deploy (as long as its lock), was held by it, or deadlocked with it (reproduced on SQL Server: ~5 s per deadlock-monitor cycle, the deploy the victim 9 of 10 times). SNAPSHOT reads take no shared locks; composes stay serialised by a transaction-owned sp_getapplock taken before any data access (row-lock-first would fail a queued compose with 3960). The #949 phase timer now starts at receipt (dispatch, in-flight-check). The #923 gate's specific 10.5 s stall is not proven to be this mechanism (see evidence).
4.4 KiB
#955 — the ~10 s StartDeployment stall (#923 gate)
Follow-up to #949 (88c9766ab), which made the caller-facing symptom honest (202 OutcomeUnknown) but left the cause open.
The leading hypothesis was lock contention around the compose's SERIALIZABLE transaction.
What the compose's transaction actually did
ComposeDeploymentAsync (added in 47960a6d5) opened a SERIALIZABLE transaction for the DataConnectionScopeState row
lock, and DraftSnapshotFactory.FromConfigDbAsync reads inside an existing transaction rather than opening its own
SNAPSHOT one. So the "one consistent SNAPSHOT read" described in the factory's remarks had silently become a SERIALIZABLE
read of ~22 config tables, whose key-range S locks were held through validate + compose + gzip + insert. Consequences:
- an uncommitted edit of any config row makes the deploy wait for it;
- a running deploy makes every edit of an already-read table wait for the deploy;
- an edit touching a table the deploy has already read and one it has not yet read deadlocks with it.
Reproduction (central SQL Server, throwaway DB, 300 tags; deploys driven through the real actor)
Exploratory probe, 10 deploys per row (5 for the last), same machine, before and after the fix:
| Concurrent writer (own connection, loop) | SERIALIZABLE (before) | SNAPSHOT + app lock (after) |
|---|---|---|
| none | p50 206 ms, max 482 ms | p50 199 ms, max 258 ms |
| AdminUI-style save (UPDATE Tag + INSERT ConfigEdit) | p50 277 ms, max 468 ms | p50 296 ms, max 679 ms |
| cross-table edit (UPDATE Tag, then UPDATE ClusterNode) | max 5 092 ms; 9 of 10 deploys failed 1205 (deadlock victim) → "StartDeployment failed on the server"; first deadlock waited one 5 s lock-monitor cycle | p50 383 ms, max 946 ms, 0 deadlocks |
| deploy bookkeeping (UPDATE Deployment + INSERT ConfigAuditLog) | p50 242 ms, max 350 ms | p50 176 ms, max 580 ms |
| edit holding a row lock 2 s | p50 1 991 ms (deploy = the writer's hold) | p50 210 ms (not held) |
So the mechanism is real: a deploy under SERIALIZABLE stalls for as long as any concurrent edit holds a lock, ~5 s per deadlock-monitor cycle on a deadlock (two cycles ≈ 10 s), or fails outright.
Fix
The compose transaction is SNAPSHOT. A snapshot read takes no shared locks: it neither waits on nor blocks an edit, and an
edit that commits after the snapshot is simply in the next deployment (the R03:3.2 contract). Composes are still serialised,
by a transaction-owned sp_getapplock (OtOpcUa/DeployCompose, 20 s) taken before any data access — under SNAPSHOT the
version clock starts at the first data access, so a compose queued behind another reads and advances the scope revision that
compose committed; taking the row lock first would fail the second with update conflict 3960.
The #949 phase timer now starts at the singleton's receipt and adds dispatch (thread-pool hand-off) and in-flight-check
(both were outside the breakdown), and also logs a slow refused or failed attempt.
Red / green (DeployComposeIsolationSqlServerTests, real SQL Server)
| Test | Red |
|---|---|
Deploy_is_not_held_by_an_uncommitted_edit_and_ships_the_committed_state |
isolation reverted to SERIALIZABLE: no reply within 10 s |
An_edit_of_an_already_read_table_does_not_wait_for_a_running_deploy |
SERIALIZABLE: the mid-read edit hits its 3 s lock timeout |
A_compose_queued_behind_another_advances_the_revision_that_compose_committed |
SNAPSHOT without the app lock: Rejected (3960) |
What is NOT established
The specific 10.5 s stall in the #923 run is not proven to be this mechanism. In that run the only config writer was the
rig's seeder, which runs (docker compose run --rm) and exits before the deploy is triggered; the in-process writers on
CONTROL (coordinator, retention, audit, the fused node's NodeDeploymentState ack) write only the deploy bookkeeping tables
in sub-second SaveChanges; and system_health showed no deadlock. The run's logs were not retained. Other places the
10 s could have gone, none of which was timed then: the ask's delivery through the singleton proxy (CONTROL-1 ↔ CONTROL-2),
thread-pool queueing before the compose (now timed as dispatch), the in-flight check (now timed), and a stall of the SQL or
CONTROL container itself. A repeat now names the phase from receipt onwards; a long gap between the API's request and the
actor's receipt would show as a slow ask with a fast breakdown.