carlos / platform Public

activator: fence pacing is apart from crash backoff (M1 review P2)

A worker refused by the R1 fence now paces with its own fenceBackoff,
cleared when a start installs; the crash backoff is untouched by
refusals. Before, a long refusal left the shared backoff at its cap,
so the first crash after recovery entered the crash loop and emitted
RFS-3-C10. Witness: a capped refusal, then install, then one crash is
a first crash.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 562113a44713cd57ba762033f298be8eabd24fc0 parent ed2c0e8
2 files changed, +83 −15
  • internal/activator/pendingwake_linux_test.go +67 −6
  • internal/activator/rootfsworkers.go +16 −9
diff --git a/internal/activator/pendingwake_linux_test.go b/internal/activator/pendingwake_linux_test.go
index 2e46f3e12..8fb2d460d 100644
--- a/internal/activator/pendingwake_linux_test.go
+++ b/internal/activator/pendingwake_linux_test.go
@@ -23,6 +23,7 @@ import (
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
+ "github.com/carlosframework/platform/internal/rolloutwords"
)
// A pending wake and the start rule (managed fleets 1b, branch review R1
@@ -1289,10 +1290,10 @@ func TestWorkerUnlabelledWakeFenced(t *testing.T) {
}
r.a.mu.Lock()
wk := r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
- restarts, crashLoop, backoff := wk.restarts, wk.crashLoop, wk.backoff
+ restarts, crashLoop, backoff, pacing := wk.restarts, wk.crashLoop, wk.backoff, wk.fenceBackoff
r.a.mu.Unlock()
- if restarts != 0 || crashLoop || backoff != sidecarRestartBase {
- t.Fatalf("restarts %d, crash loop %v, backoff %s; want no crash noted and the base backoff", restarts, crashLoop, backoff)
+ if restarts != 0 || crashLoop || backoff != 0 || pacing != sidecarRestartBase {
+ t.Fatalf("restarts %d, crash loop %v, backoff %s, fence pacing %s; want no crash noted, no crash backoff and the base fence pacing", restarts, crashLoop, backoff, pacing)
}
})
}
@@ -1332,16 +1333,76 @@ func TestWorkerUnlabelledFenceBacksOff(t *testing.T) {
}
r.a.mu.Lock()
wk := r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
- restarts, crashLoop, backoff := wk.restarts, wk.crashLoop, wk.backoff
+ restarts, crashLoop, backoff, pacing := wk.restarts, wk.crashLoop, wk.backoff, wk.fenceBackoff
r.a.mu.Unlock()
- if restarts != 0 || crashLoop || backoff != sidecarRestartMax {
- t.Fatalf("restarts %d, crash loop %v, backoff %s; want no crash and the backoff at its cap", restarts, crashLoop, backoff)
+ if restarts != 0 || crashLoop || backoff != 0 || pacing != sidecarRestartMax {
+ t.Fatalf("restarts %d, crash loop %v, backoff %s, fence pacing %s; want no crash, no crash backoff and the fence pacing at its cap", restarts, crashLoop, backoff, pacing)
}
if r.workers.alive() != 0 {
t.Fatal("a fenced worker started")
}
}
+// M1 review Astra P2-3: the fence's pacing is not crash history. A
+// worker refused by the fence long enough for its pacing to reach the cap,
+// then let through and installed, that crashes once is a first crash: the
+// crash backoff starts at sidecarRestartBase, one restart is counted, and
+// there is no crash loop and no RFS-3-C10.
+func TestFencePacingIsNoCrashHistory(t *testing.T) {
+ r := newUnlabelledWorkerRig(t)
+ r.labelled.Store(true)
+ for range 200 {
+ r.tick(t)
+ r.clk.advance(time.Second)
+ }
+ r.a.mu.Lock()
+ wk := r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
+ fencePacing := wk.fenceBackoff
+ r.a.mu.Unlock()
+ if fencePacing != sidecarRestartMax {
+ t.Fatalf("the fence's pacing is %s after 200 s of refusals; the witness needs it at its cap", fencePacing)
+ }
+ r.labelled.Store(false)
+ // The next start, at most the capped pacing away, installs.
+ for waited := time.Duration(0); r.workers.alive() == 0; waited += time.Second {
+ if waited > sidecarRestartMax {
+ t.Fatalf("no worker installed within %s of the record clearing", sidecarRestartMax)
+ }
+ r.clk.advance(time.Second)
+ r.tick(t)
+ }
+ r.a.mu.Lock()
+ wk = r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
+ fencePacing = wk.fenceBackoff
+ r.a.mu.Unlock()
+ if fencePacing != 0 {
+ t.Fatalf("installation left the fence's pacing at %s", fencePacing)
+ }
+
+ r.workers.lastWorker(t, "jobs").exit("1", "exited")
+ r.tick(t) // the crash is noted
+ r.a.mu.Lock()
+ wk = r.a.entries[r.rt.Host].rootfsWorkers["jobs"]
+ restarts, crashLoop, backoff := wk.restarts, wk.crashLoop, wk.backoff
+ r.a.mu.Unlock()
+ if restarts != 1 || crashLoop || backoff != sidecarRestartBase {
+ t.Fatalf("after one crash: restarts %d, crash loop %v, backoff %s; want 1, false and %s", restarts, crashLoop, backoff, sidecarRestartBase)
+ }
+ loop := fmt.Sprintf(rolloutwords.EventWorkerCrashLoop, "jobs")
+ var loops, exits int
+ for _, m := range r.sink.msgs() {
+ switch {
+ case m == loop:
+ loops++
+ case strings.HasPrefix(m, "worker jobs exited") && strings.HasSuffix(m, "starting it again in 2s"):
+ exits++ // RFS-3-C09 or C35, at the first crash's delay
+ }
+ }
+ if loops != 0 || exits != 1 {
+ t.Fatalf("events %q: RFS-3-C10 %d times and the first crash's RFS-3-C09 %d times; want 0 and 1", r.sink.msgs(), loops, exits)
+ }
+}
+
// R2 (fleet record labels): a fleet stop's final checkpoint must succeed
// before its lease is released. checkpointRig is one box serving host
// through the production wake and stop: a real Service over a real
diff --git a/internal/activator/rootfsworkers.go b/internal/activator/rootfsworkers.go
index 600207d8b..a1f31664d 100644
--- a/internal/activator/rootfsworkers.go
+++ b/internal/activator/rootfsworkers.go
@@ -59,9 +59,14 @@ type rootfsWorker struct {
// retryAt is when the next restart may run. Zero means an exit not yet
// noted (superviseRootfsLocked notes it, and sets it); set means the
// exit is noted and the restart waits for it.
- retryAt time.Time
- backoff time.Duration
- restarts int
+ retryAt time.Time
+ backoff time.Duration
+ // fenceBackoff paces starts the unlabelled-row fence (R1) refused,
+ // sidecarRestartBase doubling to sidecarRestartMax. It is apart from
+ // backoff, the crash history, which a refusal never touches, and is
+ // cleared when a start installs (M1 review Astra P2-3).
+ fenceBackoff time.Duration
+ restarts int
// crashLoop: the backoff reached sidecarRestartMax.
crashLoop bool
// starting marks a start in flight off a.mu; startDone is closed when
@@ -434,20 +439,22 @@ func (a *Service) runWorkerStart(ctx context.Context, wb RootfsWorkerBackend, e
switch {
case installed:
wk.started, wk.retryAt, wk.startFailed, wk.pending = now, time.Time{}, false, false
+ wk.fenceBackoff = 0
case refused && fenced.Load():
// The unlabelled-row fence (R1) refused: the record names a
// box, has copies, or cannot be read, and each start reads it
// again. Not a crash (no exit noted, no event, no crash loop),
// but paced like one, so a refused worker does not read the
- // record on every tick: the backoff doubles from
- // sidecarRestartBase to sidecarRestartMax.
+ // record on every tick: its own pacing (fenceBackoff, not the
+ // crash backoff) doubles from sidecarRestartBase to
+ // sidecarRestartMax.
wk.startFailed = true
- if wk.backoff == 0 {
- wk.backoff = sidecarRestartBase
+ if wk.fenceBackoff == 0 {
+ wk.fenceBackoff = sidecarRestartBase
} else {
- wk.backoff = min(wk.backoff*2, sidecarRestartMax)
+ wk.fenceBackoff = min(wk.fenceBackoff*2, sidecarRestartMax)
}
- wk.retryAt = now.Add(wk.backoff)
+ wk.retryAt = now.Add(wk.fenceBackoff)
case refused:
// Not a crash: the exit is treated as noted, and the start is
// asked again after the current backoff.