replicas: a join without its shared secrets halts, kept (#511)
Drill 1, F3 escrow and ruling R21 (the bounded half; see the report).
A joining copy whose wakes are refused for the instance's shared
secrets ("the new copy is waiting for the instance's shared secrets")
never starts the target. Its permitted step reached the restarted
permit-holder proof (replicaRestartedFailure), which past its bound
answered switched-failed ("the new build failed on this copy after it
switched"). The ACK put the box in Completed, so it then waited for the
secrets for ever, as box-2 did in the drill.
The resident state now records that the last wake was refused for the
secrets (noteResidentWakeLocked). With that set, the same bound, fence
and stop proof answer kept, not switched, with the reason named
(SR-4-C83). The ACK resolves the permit and halts the join, and the
box is not left allowed a target it cannot start.
Root cause of the incomplete escrow (not changed here): followerEscrowEnv
and prepareStatelessEscrow treat the escrow as complete only with all
three sealed items, and instance.key and report.token exist only if the
app writes those files itself. The drill fixture does not, so its
escrow can never be complete. That is a design decision for the
controller.
Witness: TestReplicaJoinWithoutSecretsHalts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+84
−0
internal/activator/replica_drill1_test.go+62 −0internal/activator/replicadeploy.go+14 −0internal/activator/rootfs_service.go+8 −0
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go| index f8378a134..8791e45e9 100644 |
| --- a/internal/activator/replica_drill1_test.go |
| +++ b/internal/activator/replica_drill1_test.go |
| @@ -3,6 +3,8 @@ package activator |
| import ( |
| "context" |
| "errors" |
| + "fmt" |
| + "slices" |
| "testing" |
| "time" |
| @@ -77,3 +79,63 @@ func TestReplicaCopyKeepsServingWhenCopiesRaised(t *testing.T) { |
| t.Fatalf("raising copies stopped, restarted or re-released the running copy: %+v starts %d->%d releases %d", now, starts, len(r.b.started()), len(r.b.releaseStarts())) |
| } |
| } |
| + |
| +// secretsRefusingBackend is the joining box's backend as the drill met it: |
| +// the instance's shared secrets (escrow) cannot be had, so every start of |
| +// the target is refused before anything of it runs, as |
| +// ExecBackend.prepareStatelessEscrow refuses it while the coordinator |
| +// holds the term and the escrow is not complete. |
| +type secretsRefusingBackend struct{ *wakeRelBackend } |
| + |
| +func (b *secretsRefusingBackend) prepareStatelessEscrow(context.Context, registry.Route, replicas.Identity) error { |
| + return fmt.Errorf("%w: %w", errStatelessSecretsWaiting, &replicas.CoordinatorHeldError{RetryAt: time.Now().Add(time.Minute)}) |
| +} |
| + |
| +// TestReplicaJoinWithoutSecretsHalts (#511 drill 1, R21): box b holds the |
| +// join's permit and nothing runs there; every wake of the target is |
| +// refused because the instance's shared secrets cannot be had. Within its |
| +// bound the step answers nothing. Past it, once nothing of the target is |
| +// proven to run, the step answers kept, not switched, with the reason |
| +// named: the ACK resolves the permit and halts the join, and b is not |
| +// left allowed a target it cannot start (it waited for ever, switched |
| +// and failed, in the drill). |
| +func TestReplicaJoinWithoutSecretsHalts(t *testing.T) { |
| + join := func(inc string) *replicas.Deploy { |
| + return &replicas.Deploy{ID: "deploy-v2", Incarnation: inc, Target: replicaTarget, BaselineSet: true, LastGood: replicaTarget, Phase: "released", Term: "term", Revision: 5, |
| + Swap: replicas.Swap{Order: []string{"a", "b"}, Completed: []string{"a"}, ActiveBox: "b", Permit: 5}} |
| + } |
| + r := newReplicaSetRig(t, "b", join) |
| + r.rt.Hibernate = false |
| + r.routes.set(r.rt) |
| + r.a.backend = &secretsRefusingBackend{r.b} |
| + coldWake := func() { |
| + t.Helper() |
| + r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 2}) |
| + if err := waitErr(t, r.wake(r.a)); !errors.Is(err, errStatelessSecretsWaiting) { |
| + t.Fatalf("the joining copy's wake: %v", err) |
| + } |
| + if r.a.hasEntry(r.rt.Host) || r.started("v2") { |
| + t.Fatal("the refused wake started the target") |
| + } |
| + } |
| + at := Attempt{Host: r.rt.Host, Cause: CauseRelease, Build: "v2", StagedPath: r.next.StagedPath, Mode: ModeOverlap, SchedRev: 1, ProofOnly: true} |
| + step := func() SwapResult { |
| + return r.a.ReplicaSwap(context.Background(), at, *r.store.snapshot(), "b", newestOne) |
| + } |
| + coldWake() |
| + if res := step(); res.Proven { |
| + t.Fatalf("answered with no bound passed: %+v", res) |
| + } |
| + r.clk.advance(replicaRestartBound + time.Second) |
| + coldWake() |
| + res := step() |
| + if !res.Proven || res.WebFailed || res.Outcome == SwapDone || res.Reason != replicaSecretsRefusal { |
| + t.Fatalf("not answered kept for want of the shared secrets: %+v", res) |
| + } |
| + cur := *r.store.snapshot() |
| + ack := replicas.DeployChange{Op: "ack", ID: cur.ID, Box: "b", Revision: cur.Revision, Target: cur.Target, Permit: cur.Swap.Permit} |
| + next, err := replicas.NextDeploy(cur, ack, replicas.Coordinator{}, time.Now()) |
| + if err != nil || next.PermitOutstanding() || !next.Swap.Halted || slices.Contains(next.Swap.Completed, "b") || next.Allows("b", r.inc, replicaTarget.Digest) { |
| + t.Fatalf("the join did not halt with b off the target: %v %+v", err, next.Swap) |
| + } |
| +} |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go| index e6e15a77f..2a84e71d4 100644 |
| --- a/internal/activator/replicadeploy.go |
| +++ b/internal/activator/replicadeploy.go |
| @@ -479,6 +479,8 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| cancel() |
| a.mu.Lock() |
| releasing := a.releaseOps[at.Host] != nil |
| + st := a.residents[at.Host] |
| + secrets := st != nil && st.secrets |
| a.mu.Unlock() |
| proven := err == nil || errors.Is(err, ErrStopUnproven) && !releasing && !a.StopUncertain(at.Host) |
| a.LiftFenceAs(at.Host, key.permit, owner) |
| @@ -487,5 +489,17 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| res.Reason = "this copy holds the permit with nothing running; its stop is not proven yet, so the step stays open" |
| return res, true |
| } |
| + if secrets { |
| + // Its wakes were refused for the instance's shared secrets (a |
| + // joining copy whose escrow is not complete; #511 drill 1, R21): |
| + // the target never started here. The answer is kept, not |
| + // switched, so the ACK resolves the permit and halts the deploy, |
| + // and this copy stops asking for a build it cannot start. |
| + return SwapResult{Outcome: SwapAbandoned, Proven: true, Reason: replicaSecretsRefusal}, true |
| + } |
| return SwapResult{Outcome: SwapAbandoned, Proven: true, WebFailed: true, Reason: "the new build failed on this copy after it switched and did not come back; nothing of it runs"}, true |
| } |
| + |
| +// replicaSecretsRefusal is a permitted step's answer when its copy never |
| +// started for want of the instance's shared secrets. copy SR-4-C83 |
| +const replicaSecretsRefusal = "the new copy could not get the instance's shared secrets, so it did not start and the deploy stopped. existing copies keep serving" |
diff --git a/internal/activator/rootfs_service.go b/internal/activator/rootfs_service.go| index 3b2fb5f22..96d5191c6 100644 |
| --- a/internal/activator/rootfs_service.go |
| +++ b/internal/activator/rootfs_service.go |
| @@ -423,6 +423,11 @@ type residentState struct { |
| // nothing and a request is not held back by it; only the tick waits, so |
| // it does not ask the store for the lease every residentPoll. |
| waitUntil time.Time |
| + // secrets: its last wake was refused because the instance's shared |
| + // secrets could not be had (errStatelessSecretsWaiting). A copy's |
| + // permitted step reads it to answer instead of waiting on them for |
| + // ever (replicaRestartedFailure; #511 drill 1, R21). |
| + secrets bool |
| } |
| // errResidentBackoff is begin's answer for a resident inside its backoff: |
| @@ -1072,6 +1077,9 @@ func (a *Service) noteResidentWakeLocked(e *actEntry, err error) { |
| st.starting = false |
| } |
| } |
| + if e.route.Resident() && (err != nil || a.residents[e.host] != nil) { |
| + a.residentLocked(e.host).secrets = errors.Is(err, errStatelessSecretsWaiting) |
| + } |
| if err == nil || !e.route.Resident() { |
| return |
| } |