fix(controlplane): condition the dispatch flip on the guard's RowVersion; one deadline source; align IdentityModel pins
Re-review 1: HandleDispatch's terminal guard and its AwaitingApplyAcks flip read the row separately, so a lost-dispatch closure committed between them was silently reopened. The flip now carries the RowVersion the guard read; a change in between is a concurrency conflict (nothing seeded, nothing published, coordinator reset). Pinned on real SQL Server with a closure injected between the two reads (fails without the fix). AdminOps' apply deadline and the coordinator's now both read DeployTimings.ApplyDeadline, passed explicitly to both singletons. Microsoft.IdentityModel.Protocols(.OpenIdConnect) pinned to 8.11.0 and referenced directly by the Security project, so the whole IdentityModel family resolves 8.11.0 (fresh restore clean of NU190x/NU1605). Refs #733 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
+71
@@ -311,6 +311,77 @@ public sealed class ConfigPublishCoordinatorRecoveryTests : ControlPlaneActorTes
|
||||
}, duration: PresenceBudget);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Re-review 1 — the reopen race. AdminOps' lost-dispatch closure commits TimedOut AFTER the coordinator's
|
||||
/// terminal guard read the row as Dispatching but BEFORE the AwaitingApplyAcks flip. The flip is
|
||||
/// conditioned on the guard's RowVersion, so on SQL Server it becomes a concurrency conflict and the row
|
||||
/// stays TimedOut with no expected set. Positive control: the coordinator is not wedged — the next live
|
||||
/// dispatch is seeded and flipped.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[Trait("Category", "SchemaCompliance")]
|
||||
public async Task On_sql_server_a_closure_between_guard_and_flip_is_not_reopened()
|
||||
{
|
||||
using var sql = new SqlServerTestDatabase();
|
||||
var inner = sql.Factory();
|
||||
SeedNodes(inner, "site-a-1:4053");
|
||||
var interposer = new InterposingDbFactory(inner);
|
||||
var coordinator = Sys.ActorOf(ConfigPublishCoordinator.Props(interposer, NoTimeout));
|
||||
await Sys.ActorSelection(coordinator.Path).ResolveOne(PresenceBudget); // PreStart ran over an empty table
|
||||
|
||||
// The race proper: a new Dispatching row whose dispatch is interleaved with an AdminOps-style closure.
|
||||
var victim = SeedDeployment(inner, DeploymentStatus.Dispatching, DateTime.UtcNow);
|
||||
interposer.OnSecondCreate(() =>
|
||||
{
|
||||
using var db = sql.NewContext();
|
||||
db.Database.ExecuteSqlRaw(
|
||||
"UPDATE Deployment SET Status = {0}, FailureReason = N'closed as lost' WHERE DeploymentId = {1}",
|
||||
(int)DeploymentStatus.TimedOut, victim.Value);
|
||||
});
|
||||
coordinator.Tell(new DispatchDeployment(victim, TestRevision, CorrelationId.NewId()));
|
||||
AwaitAssert(() => interposer.Fired.ShouldBeTrue(), duration: PresenceBudget);
|
||||
|
||||
// Positive control + ordering: a live row dispatched after it IS flipped, so the victim's dispatch was processed.
|
||||
var live = SeedDeployment(inner, DeploymentStatus.Dispatching, DateTime.UtcNow);
|
||||
coordinator.Tell(new DispatchDeployment(live, TestRevision, CorrelationId.NewId()));
|
||||
AwaitAssert(() =>
|
||||
{
|
||||
using var db = sql.NewContext();
|
||||
db.Deployments.AsNoTracking().Single(d => d.DeploymentId == live.Value).Status
|
||||
.ShouldBe(DeploymentStatus.AwaitingApplyAcks);
|
||||
}, duration: PresenceBudget);
|
||||
|
||||
using var verify = sql.NewContext();
|
||||
verify.Deployments.AsNoTracking().Single(d => d.DeploymentId == victim.Value).Status
|
||||
.ShouldBe(DeploymentStatus.TimedOut, "the closure must not be reopened");
|
||||
verify.NodeDeploymentStates.Count(s => s.DeploymentId == victim.Value).ShouldBe(0);
|
||||
}
|
||||
|
||||
/// <summary>Runs an action just before handing out the SECOND context after arming (HandleDispatch: guard, then flip).</summary>
|
||||
private sealed class InterposingDbFactory(IDbContextFactory<OtOpcUaConfigDbContext> inner)
|
||||
: IDbContextFactory<OtOpcUaConfigDbContext>
|
||||
{
|
||||
private Action? _action;
|
||||
private int _countdown;
|
||||
public volatile bool Fired;
|
||||
|
||||
public void OnSecondCreate(Action action)
|
||||
{
|
||||
_action = action;
|
||||
Volatile.Write(ref _countdown, 2);
|
||||
}
|
||||
|
||||
public OtOpcUaConfigDbContext CreateDbContext()
|
||||
{
|
||||
if (Volatile.Read(ref _countdown) > 0 && Interlocked.Decrement(ref _countdown) == 0)
|
||||
{
|
||||
_action?.Invoke();
|
||||
Fired = true;
|
||||
}
|
||||
return inner.CreateDbContext();
|
||||
}
|
||||
}
|
||||
|
||||
private static DeploymentId SeedDeployment(
|
||||
IDbContextFactory<OtOpcUaConfigDbContext> dbFactory, DeploymentStatus status, DateTime createdAtUtc)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user