host: bound the staging lease release on the cut's error paths
cutRun.lease released the staging lease with context.Background() when the staging writer or the mirror could not be built right after taking it, while the normal path (releaseLease) bounds the release to 10 s. A store that hangs at that moment hung the cut's goroutine (audit host.md "Bugs found along the way", ASTRA item 6). Both error paths now go through releaseLease, so they get its bound; a failed release is now logged there instead of dropped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+69
−2
internal/host/movescut.go+6 −2internal/host/movescut_leaserelease_test.go+63 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/host/movescut.go b/internal/host/movescut.go| index 815bffc28..2a2a4836d 100644 |
| --- a/internal/host/movescut.go |
| +++ b/internal/host/movescut.go |
| @@ -907,14 +907,18 @@ func (c *cutRun) lease(ctx context.Context) (waiting bool, err error) { |
| } |
| return false, fmt.Errorf("staging lease: %w", err) |
| } |
| + // The error paths release through releaseLease, with its bound: a store |
| + // that hangs at this moment must not hang the cut's goroutine. |
| stg, err := c.w.staging(ctx, tgt.DataBucketRegion) |
| if err != nil { |
| - rel(context.Background()) |
| + c.release = rel |
| + c.releaseLease() |
| return false, err |
| } |
| own, err := c.w.mirror(ctx, tgt.DataBucketRegion) |
| if err != nil { |
| - rel(context.Background()) |
| + c.release = rel |
| + c.releaseLease() |
| return false, err |
| } |
| c.gm = &guardedMirror{w: stg, g: moves.Guarded{Lease: held, Now: cfg.Now}, dst: tgt.DataBucket, own: own} |
diff --git a/internal/host/movescut_leaserelease_test.go b/internal/host/movescut_leaserelease_test.go| new file mode 100644 |
| index 000000000..f23881f82 |
| --- /dev/null |
| +++ b/internal/host/movescut_leaserelease_test.go |
| @@ -0,0 +1,63 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/lease" |
| + "github.com/carlosframework/platform/internal/moves" |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// The cut's staging lease is released with a bounded context on every |
| +// path: when the staging writer or the mirror cannot be built right after |
| +// the lease is taken, as on the normal release (releaseLease's 10 s). |
| +func TestCutReleasesStagingLeaseBoundedOnError(t *testing.T) { |
| + for _, fail := range []string{"staging", "mirror"} { |
| + t.Run(fail, func(t *testing.T) { |
| + h := newCutHarness(t) |
| + h.ready(t) |
| + // Stopped, with execution given up: the next pass is the final |
| + // round, which takes the cut's own lease (cutRun.lease). The |
| + // requested phase's source round has a lease of its own. |
| + h.crashAt = "after-exec-none" |
| + h.cut(t) |
| + h.crashPass(t) |
| + if m := h.move(t); m.CutPhase != provision.CutStopped { |
| + t.Fatalf("the fixture did not stop: %+v", m) |
| + } |
| + var released []time.Duration |
| + h.cfg.StagingLease = func(context.Context, string, string) (moves.SafeUntilGuard, func(context.Context) error, error) { |
| + return h.lease, func(ctx context.Context) error { |
| + d, ok := ctx.Deadline() |
| + if !ok { |
| + released = append(released, -1) |
| + return nil |
| + } |
| + released = append(released, time.Until(d)) |
| + return nil |
| + }, nil |
| + } |
| + broken := errors.New("injected " + fail + " failure") |
| + switch fail { |
| + case "staging": |
| + h.cfg.Staging = func(context.Context, string) (lease.StagingWriter, error) { return nil, broken } |
| + case "mirror": |
| + h.cfg.Mirror = func(context.Context, string) (lease.MirrorStore, error) { return nil, broken } |
| + } |
| + h.freshWorker() // the worker memoizes its staging writer and mirrors |
| + _ = movesPass(context.Background(), h.s, h.w()) |
| + if m := h.move(t); m.CutPhase != provision.CutStopped { |
| + t.Fatalf("the failed final round moved the cut on: %+v", m) |
| + } |
| + if len(released) != 1 { |
| + t.Fatalf("the lease was released %d times, want once", len(released)) |
| + } |
| + if d := released[0]; d <= 0 || d > 10*time.Second { |
| + t.Fatalf("released with deadline %v away, want a bound of at most 10s", d) |
| + } |
| + }) |
| + } |
| +} |