carlos / platform Public

lease witness: stop the real-S3 renewer before the stale-write check (R2 P2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 79bdfd695483e9d55d42b6f3ff4f732285b8b964 parent 348c46e
1 file changed, +10 −2
  • internal/lease/pause_rootrunner_linux_test.go +10 −2

CI passed — run details

diff --git a/internal/lease/pause_rootrunner_linux_test.go b/internal/lease/pause_rootrunner_linux_test.go
index e9510f908..6f48b540e 100644
--- a/internal/lease/pause_rootrunner_linux_test.go
+++ b/internal/lease/pause_rootrunner_linux_test.go
@@ -192,6 +192,9 @@ func TestRootRenewalAgainstRealS3(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ // The renewer is stopped on every path (stop is idempotent): no
+ // background writes outlive the test.
+ t.Cleanup(func() { h.rn.stop() })
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(witnessRegion))
if err != nil {
t.Fatal(err)
@@ -220,6 +223,11 @@ func TestRootRenewalAgainstRealS3(t *testing.T) {
if etag1 == etag0 || !l1.ExpiresAt.After(l0.ExpiresAt.Add(ttl/2)) || l1.Generation != l0.Generation || l1.Owner != l0.Owner {
t.Fatalf("no renewal landed: %s %+v -> %s %+v", etag0, l0, etag1, l1)
}
+ // Stop and join the renewer before the stale write, so no ordinary
+ // renewal can change the lock under the assertion below; take the
+ // baseline after it has stopped.
+ h.rn.stop()
+ etag1, _ = read()
stale := &litestream.Lease{Generation: l0.Generation, ETag: etag0, Owner: l0.Owner}
if _, err := renewLease(ctx, h.rn.client, h.leaser, stale, time.Now().Add(ttl)); !errors.Is(err, litestream.ErrLeaseNotHeld) {
t.Fatalf("a renewal on a stale ETag: %v, want ErrLeaseNotHeld", err)
@@ -228,6 +236,6 @@ func TestRootRenewalAgainstRealS3(t *testing.T) {
t.Fatal("the stale renewal changed the lock")
}
t.Logf("PASS: renewed %s -> %s, expiry %s -> %s; stale ETag refused", etag0, etag1, l0.ExpiresAt.UTC().Format(time.RFC3339Nano), l1.ExpiresAt.UTC().Format(time.RFC3339Nano))
- // Release needs DeleteObject, which the runner's role lacks; the lock
- // lapses in 30 s under the runner's own prefix.
+ // Release needs DeleteObject, which the runner's role lacks; with the
+ // renewer stopped the lock lapses in 30 s under the runner's own prefix.
}