replicas: bound the config and shared-secrets waits (#511)
Drill 1, the two waits flagged in the report, bounded as ruled. Config wait (R20): releaseConfigBound = residentPoll + workerStartBound (the bound replicaRestartBound already gives a copy that cannot start; about 32 s, some ten config sync ticks). The first wait of a host is noted in memory (Service.releaseConfigSince). Past the bound, the attempt begins through the same writer and is recorded failed with nothing run, and the wake says why (errReleaseConfigHeld, SR-4-C90; it is errReplicaReleaseFailed to every classifier). The copy then meets the failed attempt until a retry, which waits again from the start. Shared-secrets wait of a box added after a deploy is done (R21b): bound replicaRestartBound, counted from the first refusal (residentState.secretsSince). Past it, the wake's refusal says SR-4-C83 (secretsRefused, wrapping the same refusal), and the tick asks again only every configRefusedRetryAfter. SR-4-C83 now reads "the new copy could not get the instance's shared secrets, so it did not start. existing copies keep serving", which also serves the halted join. Witnesses: TestReleaseConfigWaitHeldAsFailed and TestDoneCopyRefusesWithoutSecrets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+196
−14
internal/activator/activator.go+4 −0internal/activator/replica_drill1_test.go+71 −0internal/activator/replicadeploy.go+37 −4internal/activator/rootfs_service.go+17 −6internal/activator/stateless.go+2 −2internal/activator/statelessrelease.go+65 −2
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index a344966bb..214148f23 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -1325,6 +1325,10 @@ type Service struct { |
| // with no generation at all and no switch evidence, and since when |
| // (replicaRestartedFailure): only the bound's clock, never evidence. |
| replicaNoGen map[string]replicaSwitch |
| + // releaseConfigSince is, per host, when a stateless release first |
| + // waited for its instance's config file (releaseConfigWait), for |
| + // releaseConfigBound (#511 drill 1, R20). Under mu. |
| + releaseConfigSince map[string]time.Time |
| // Startup gates admission while the agent recovers installations. Set before publication. |
| Startup <-chan struct{} |
diff --git a/internal/activator/replica_drill1_test.go b/internal/activator/replica_drill1_test.go| index db78280aa..b1b8ae416 100644 |
| --- a/internal/activator/replica_drill1_test.go |
| +++ b/internal/activator/replica_drill1_test.go |
| @@ -383,3 +383,74 @@ func TestStatelessEscrowRecordsAbsence(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// TestReleaseConfigWaitHeldAsFailed (#511 drill 1, R20 bound): a release |
| +// whose configuration is never written waits releaseConfigBound and no |
| +// longer. Within it, nothing begins. Past it, the attempt begins and is |
| +// held as failed with nothing run, its reason named (SR-4-C90); the copy |
| +// then meets the failed attempt, as any failed release, until a retry. |
| +func TestReleaseConfigWaitHeldAsFailed(t *testing.T) { |
| + r := newWakeRelRig(t) |
| + store := wireStatelessRig(r) |
| + r.a.backend = &configWaitBackend{wakeRelBackend: r.b} |
| + r.rt.Hibernate, r.rt.Stateless = false, true |
| + r.routes.set(r.rt) |
| + r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 1}) |
| + var wait *releaseConfigWait |
| + if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || store.snapshot() != nil { |
| + t.Fatalf("within the bound: %v, record %+v", err, store.snapshot()) |
| + } |
| + r.clk.advance(releaseConfigBound / 2) |
| + if err := waitErr(t, r.wake(r.a)); !errors.As(err, &wait) || store.snapshot() != nil { |
| + t.Fatalf("still within the bound: %v, record %+v", err, store.snapshot()) |
| + } |
| + r.clk.advance(releaseConfigBound) |
| + err := waitErr(t, r.wake(r.a)) |
| + if !errors.Is(err, errReleaseConfigHeld) || !errors.Is(err, errReplicaReleaseFailed) { |
| + t.Fatalf("past the bound: %v", err) |
| + } |
| + if d := store.snapshot(); d == nil || d.Phase != "failed" || len(r.b.releaseStarts()) != 0 || r.a.hasEntry(r.rt.Host) { |
| + t.Fatalf("not held as failed with nothing run: %+v, releases %d", d, len(r.b.releaseStarts())) |
| + } |
| + if err := waitErr(t, r.wake(r.a)); !errors.Is(err, errReplicaReleaseFailed) || len(r.b.releaseStarts()) != 0 { |
| + t.Fatalf("the held attempt did not stay failed: %v", err) |
| + } |
| +} |
| + |
| +// TestDoneCopyRefusesWithoutSecrets (#511 drill 1, R21b bound): after a |
| +// deploy is done, a box added to the assignment starts the target with no |
| +// permit. While the instance's shared secrets cannot be had, it waits |
| +// replicaRestartBound; past it, its wakes refuse with the R21 refusal |
| +// (SR-4-C83), still the same refusal to every classifier, and nothing of |
| +// the target starts. |
| +func TestDoneCopyRefusesWithoutSecrets(t *testing.T) { |
| + done := func(inc string) *replicas.Deploy { |
| + return &replicas.Deploy{ID: "deploy-v2", Incarnation: inc, Target: replicaTarget, BaselineSet: true, LastGood: replicaTarget, Phase: "done", Term: "term", Revision: 7, |
| + Swap: replicas.Swap{Order: []string{"a"}, Completed: []string{"a"}}} |
| + } |
| + r := newReplicaSetRig(t, "b", done) |
| + r.rt.Hibernate = false |
| + r.routes.set(r.rt) |
| + r.a.backend = &secretsRefusingBackend{r.b} |
| + wake := func() error { |
| + t.Helper() |
| + r.setPlan(WakePlan{Boot: r.next, Mode: ModeOverlap, Token: 2}) |
| + err := waitErr(t, r.wake(r.a)) |
| + if r.a.hasEntry(r.rt.Host) || r.started("v2") { |
| + t.Fatal("a wake without the shared secrets started the target") |
| + } |
| + return err |
| + } |
| + if err := wake(); !errors.Is(err, errStatelessSecretsWaiting) || err.Error() == replicaSecretsRefusal { |
| + t.Fatalf("within the bound: %v", err) |
| + } |
| + r.clk.advance(replicaRestartBound + time.Second) |
| + err := wake() |
| + var refused *secretsRefused |
| + if !errors.As(err, &refused) || err.Error() != replicaSecretsRefusal || !errors.Is(err, errStatelessSecretsWaiting) { |
| + t.Fatalf("past the bound: %v", err) |
| + } |
| + if d := residentOwnerWait(err); d != configRefusedRetryAfter*time.Second { |
| + t.Fatalf("the refusal is asked again after %s", d) |
| + } |
| +} |
diff --git a/internal/activator/replicadeploy.go b/internal/activator/replicadeploy.go| index 2a84e71d4..acf8d42e3 100644 |
| --- a/internal/activator/replicadeploy.go |
| +++ b/internal/activator/replicadeploy.go |
| @@ -480,7 +480,7 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| a.mu.Lock() |
| releasing := a.releaseOps[at.Host] != nil |
| st := a.residents[at.Host] |
| - secrets := st != nil && st.secrets |
| + secrets := st != nil && !st.secretsSince.IsZero() |
| a.mu.Unlock() |
| proven := err == nil || errors.Is(err, ErrStopUnproven) && !releasing && !a.StopUncertain(at.Host) |
| a.LiftFenceAs(at.Host, key.permit, owner) |
| @@ -500,6 +500,39 @@ func (a *Service) replicaRestartedFailure(ctx context.Context, at Attempt, deplo |
| 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" |
| +// replicaSecretsRefusal is the answer of a copy that never started for |
| +// want of the instance's shared secrets: its permitted step's, which halts |
| +// the deploy, and, past replicaRestartBound, its wakes' (secretsRefusal). |
| +// copy SR-4-C83 |
| +const replicaSecretsRefusal = "the new copy could not get the instance's shared secrets, so it did not start. existing copies keep serving" |
| + |
| +// secretsRefused is a wake refused for the instance's shared secrets past |
| +// replicaRestartBound since the first such refusal (#511 drill 1, R21b): |
| +// a copy that joined with no permit (a deploy already done) says plainly |
| +// that it cannot start, and asks again only every configRefusedRetryAfter. |
| +// It wraps the refusal it replaces, so it is the same refusal to every |
| +// classifier. |
| +type secretsRefused struct{ err error } |
| + |
| +func (e *secretsRefused) Error() string { return replicaSecretsRefusal } |
| +func (e *secretsRefused) Unwrap() error { return e.err } |
| + |
| +// secretsRefusal is err, a stateless wake's refusal, said as |
| +// replicaSecretsRefusal once host's wakes have been refused for the shared |
| +// secrets for replicaRestartBound. |
| +func (a *Service) secretsRefusal(host string, err error) error { |
| + if !errors.Is(err, errStatelessSecretsWaiting) { |
| + return err |
| + } |
| + a.mu.Lock() |
| + var since time.Time |
| + if st := a.residents[host]; st != nil { |
| + since = st.secretsSince |
| + } |
| + expired := !since.IsZero() && !a.now().Before(since.Add(replicaRestartBound)) |
| + a.mu.Unlock() |
| + if !expired { |
| + return err |
| + } |
| + return &secretsRefused{err: err} |
| +} |
diff --git a/internal/activator/rootfs_service.go b/internal/activator/rootfs_service.go| index d319eb273..3c5f81206 100644 |
| --- a/internal/activator/rootfs_service.go |
| +++ b/internal/activator/rootfs_service.go |
| @@ -423,11 +423,13 @@ 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 |
| + // secretsSince: since when its wakes, the last one included, have been |
| + // refused because the instance's shared secrets could not be had |
| + // (errStatelessSecretsWaiting); zero otherwise. A copy's permitted step |
| + // reads it to answer instead of waiting on them for ever |
| + // (replicaRestartedFailure), and past replicaRestartBound a wake says |
| + // so plainly (secretsRefusal; #511 drill 1, R21 and R21b). |
| + secretsSince time.Time |
| } |
| // errResidentBackoff is begin's answer for a resident inside its backoff: |
| @@ -522,9 +524,12 @@ func residentOwnerWait(err error) time.Duration { |
| var held *errLeaseHeld |
| var refused *errConfigRefused |
| var config *releaseConfigWait |
| + var secrets *secretsRefused |
| switch { |
| case errors.As(err, &config): |
| return releaseConfigPace |
| + case errors.As(err, &secrets): |
| + return configRefusedRetryAfter * time.Second |
| case errors.As(err, &held): |
| return held.retryAfter |
| case errors.As(err, &refused): |
| @@ -1081,7 +1086,13 @@ func (a *Service) noteResidentWakeLocked(e *actEntry, err error) { |
| } |
| } |
| if e.route.Resident() && (err != nil || a.residents[e.host] != nil) { |
| - a.residentLocked(e.host).secrets = errors.Is(err, errStatelessSecretsWaiting) |
| + st := a.residentLocked(e.host) |
| + switch { |
| + case !errors.Is(err, errStatelessSecretsWaiting): |
| + st.secretsSince = time.Time{} |
| + case st.secretsSince.IsZero(): |
| + st.secretsSince = a.now() |
| + } |
| } |
| if err == nil || !e.route.Resident() { |
| return |
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go| index b2f36f2df..51f3f781a 100644 |
| --- a/internal/activator/stateless.go |
| +++ b/internal/activator/stateless.go |
| @@ -177,7 +177,7 @@ func (a *Service) doStatelessWake(ctx context.Context, e *actEntry, id release.S |
| if a.releaseOpen(rt.Host) { |
| w.stopOutcome.uncertain = true |
| } |
| - return w, err |
| + return w, a.secretsRefusal(rt.Host, err) |
| } |
| ctx = prepared |
| gate := func() error { |
| @@ -229,7 +229,7 @@ func (a *Service) doStatelessWake(ctx context.Context, e *actEntry, id release.S |
| w.failed, w.failReason = &id, err.Error() |
| return w, &wakeModeChange{id: *in.plan.Fallback} |
| } |
| - return w, err |
| + return w, a.secretsRefusal(rt.Host, err) |
| } |
| if !a.wakeAllowed(rt.Host) || ctx.Err() != nil { |
| a.cleanupFailedWake(ctx, e, rt, w, nil) |
diff --git a/internal/activator/statelessrelease.go b/internal/activator/statelessrelease.go| index 0bc9da0c9..bafa28163 100644 |
| --- a/internal/activator/statelessrelease.go |
| +++ b/internal/activator/statelessrelease.go |
| @@ -182,10 +182,20 @@ func (a *Service) prepareStatelessRelease(ctx context.Context, rt registry.Route |
| } |
| // R20 (#511 drill 1): a release never runs before its instance's |
| // config is written here. It waits, before any term or attempt, so no |
| - // attempt is consumed and nothing is recorded as failed. |
| + // attempt is consumed and nothing is recorded as failed. Past |
| + // releaseConfigBound it waits no more: the attempt begins and is held |
| + // as failed, with nothing run (configHeld). |
| + configHeld := false |
| if g, ok := a.backend.(releaseConfigGate); ok && rt.Rootfs() { |
| - if err := g.releaseConfigWait(ctx, rt); err != nil { |
| + err := g.releaseConfigWait(ctx, rt) |
| + var wait *releaseConfigWait |
| + switch { |
| + case err == nil: |
| + a.releaseConfigDone(rt.Host) |
| + case !errors.As(err, &wait) || !a.releaseConfigExpired(rt.Host): |
| return "", err |
| + default: |
| + configHeld = true |
| } |
| } |
| if a.Coordinator == nil { |
| @@ -272,6 +282,16 @@ func (a *Service) prepareStatelessRelease(ctx context.Context, rt registry.Route |
| // release that passed, #511 F11); the record's attempt decides. |
| return a.refusedStep(ctx, rt, identity, target, deployID, err) |
| } |
| + if configHeld { |
| + // Held as failed, with nothing run: the release never ran without |
| + // its configuration. An explicit retry begins a new attempt, which |
| + // waits again from the start. |
| + if _, err := change("failed"); err != nil { |
| + return deployID, stepError(err) |
| + } |
| + a.releaseConfigDone(rt.Host) |
| + return deployID, errReleaseConfigHeld |
| + } |
| // Only this path discards stateful good-build inference. The durable |
| // deploy ID, canonical target and lifetime decide whether work is due. |
| rt.GoodVersion, rt.GoodDigest, rt.GoodDemand = "", "", "" |
| @@ -440,3 +460,46 @@ func (a *Service) ReplicaRelease(ctx context.Context, at Attempt) error { |
| _, err = a.prepareStatelessRelease(observed, launch, id, a.ReplicaDeployID) |
| return err |
| } |
| + |
| +// releaseConfigBound is how long a stateless release waits for its |
| +// instance's config file before its attempt is held as failed (#511 drill |
| +// 1, R20): the bound a permitted step gives a copy that cannot start |
| +// (residentPoll + workerStartBound, as replicaRestartBound), about 32 s, |
| +// some ten config sync ticks. |
| +var releaseConfigBound = residentPoll + workerStartBound |
| + |
| +// errReleaseConfigHeld is the answer of the attempt held as failed past |
| +// releaseConfigBound: the release command never ran. It is the attempt's |
| +// failed release to every classifier (errReplicaReleaseFailed). |
| +var errReleaseConfigHeld error = releaseConfigHeld{} |
| + |
| +type releaseConfigHeld struct{} |
| + |
| +// copy SR-4-C90 |
| +func (releaseConfigHeld) Error() string { |
| + return "the release did not run: this instance's configuration was not written on this box in time, so the release is held as failed. retry it once the configuration is there" |
| +} |
| +func (releaseConfigHeld) Unwrap() error { return errReplicaReleaseFailed } |
| + |
| +// releaseConfigExpired notes host's config wait, from its first, and |
| +// reports whether it has lasted releaseConfigBound. |
| +func (a *Service) releaseConfigExpired(host string) bool { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + now := a.now() |
| + since, ok := a.releaseConfigSince[host] |
| + if !ok { |
| + if a.releaseConfigSince == nil { |
| + a.releaseConfigSince = make(map[string]time.Time) |
| + } |
| + a.releaseConfigSince[host], since = now, now |
| + } |
| + return !now.Before(since.Add(releaseConfigBound)) |
| +} |
| + |
| +// releaseConfigDone ends host's config wait. |
| +func (a *Service) releaseConfigDone(host string) { |
| + a.mu.Lock() |
| + delete(a.releaseConfigSince, host) |
| + a.mu.Unlock() |
| +} |