console tests: a refused admission's hub check waits for the reservation's release (rootfs plan 6 task 10)
CI at 8f656c94: TestAdmissionRefusedWhileDrainingEndsWithC37 saw its id still "reserved". Root cause is the test's ordering, not a leak: a refused admission sends its End from refuseSession, and serveInteractive's deferred release (unconditional on every non-activated return) drops the reservation as it returns, just after. The test read the hub as soon as it had the End. A 50 ms sleep before that release reproduces the CI failure every time. The hub gains an afterRelease seam beside afterReserve; the three tests that check the hub after a refused End (the drain C37 test, the failed admission and the hung grant PUT) wait on the release event instead of reading at once or polling a timer. A reservation that is never released still fails them (waitForSignal's bound).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/apiinteractive_lifetimes_test.go+2 −4internal/console/apiinteractive_test.go+37 −10internal/console/interactivehub.go+9 −3
CI cancelled — superseded by a newer push — run details
Intent
<task-notification> <task-id>b94mi01fq</task-id> <tool-use-id>toolu_01EMM1om9afoLWY2aCdh5C2c</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/b94mi01fq.output</output-file> <status>completed</status> <summary>Background command "Run Astra whole-branch round 2" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bkhy63ufl</task-id> <tool-use-id>toolu_01FmsJHAF5qreBgrBBYBycwm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bkhy63ufl.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on the R1 fix" completed (exit code 0)</summary> </task-notification>
diff --git a/internal/console/apiinteractive_lifetimes_test.go b/internal/console/apiinteractive_lifetimes_test.go| index 3a6709a0a..246ee86a8 100644 |
| --- a/internal/console/apiinteractive_lifetimes_test.go |
| +++ b/internal/console/apiinteractive_lifetimes_test.go |
| @@ -14,7 +14,6 @@ import ( |
| "sort" |
| "strings" |
| "sync" |
| - "sync/atomic" |
| "testing" |
| "time" |
| @@ -141,8 +140,7 @@ func TestAdmissionRefusedWhileDrainingEndsWithC37(t *testing.T) { |
| } |
| t.Cleanup(held.done) |
| ixCutover(t, fx) |
| - var reservedID atomic.Value |
| - fx.srv.interactive.afterReserve = func(id string) { reservedID.Store(id) } |
| + watch := ixWatchReservation(fx.srv.interactive) |
| snap := ixSnapshot(t, fx, ixHost) |
| ws, err := ixDial(t, fx.ts.URL, fx.ixURL(ixHost), fx.alice) |
| if err != nil { |
| @@ -153,7 +151,7 @@ func TestAdmissionRefusedWhileDrainingEndsWithC37(t *testing.T) { |
| t.Fatalf("end %+v, want refused with RFS-6-C37", e) |
| } |
| ixNothingWritten(t, fx, ixHost, snap) |
| - reserved, _ := reservedID.Load().(string) |
| + reserved := watch.waitReleased(t) |
| if reserved == "" || hubState(fx.srv.interactive, reserved) != "" || hubCount(fx.srv.interactive) != 0 { |
| t.Fatalf("the hub holds %q as %q", reserved, hubState(fx.srv.interactive, reserved)) |
| } |
diff --git a/internal/console/apiinteractive_test.go b/internal/console/apiinteractive_test.go| index e7d844c1a..6f7a5c0fd 100644 |
| --- a/internal/console/apiinteractive_test.go |
| +++ b/internal/console/apiinteractive_test.go |
| @@ -948,6 +948,37 @@ func TestAdmissionHoldsItsReservationUntilRegistered(t *testing.T) { |
| ixWaitEvents(t, fx, "interactive-end", 1) |
| } |
| +// ixReservation watches one admission's reservation through the hub's |
| +// seams: the id reserved, and an event when that id is released. A refused |
| +// admission releases its reservation as serveInteractive returns, just after |
| +// the CLI has its End, so a test reads the hub only after the event. |
| +type ixReservation struct { |
| + id atomic.Value |
| + released chan struct{} |
| +} |
| + |
| +func ixWatchReservation(h *interactiveHub) *ixReservation { |
| + r := &ixReservation{released: make(chan struct{})} |
| + var once sync.Once |
| + h.afterReserve = func(id string) { r.id.Store(id) } |
| + h.afterRelease = func(id string) { |
| + if got, _ := r.id.Load().(string); got == id { |
| + once.Do(func() { close(r.released) }) |
| + } |
| + } |
| + return r |
| +} |
| + |
| +// waitReleased waits for the release (failing after waitForSignal's bound, |
| +// which a reservation that is never released, a leak, hits) and returns |
| +// the id. |
| +func (r *ixReservation) waitReleased(t *testing.T) string { |
| + t.Helper() |
| + waitForSignal(t, r.released, "the reservation's release") |
| + id, _ := r.id.Load().(string) |
| + return id |
| +} |
| + |
| func TestAFailedAdmissionReleasesItsReservation(t *testing.T) { |
| fx := newIxFx(t, "code-ix-failed") |
| ws, err := ixDial(t, fx.ts.URL, fx.ixURL(ixHost), fx.alice) |
| @@ -956,15 +987,14 @@ func TestAFailedAdmissionReleasesItsReservation(t *testing.T) { |
| } |
| // The door's checks passed; a move begins before the admission. |
| ixPutRecord(t, fx, provision.Record{Host: ixHost, Channel: "stable", Region: "uk", Move: &provision.MoveState{ID: "mv_1", To: "ie"}}) |
| - var reservedID atomic.Value |
| - fx.srv.interactive.afterReserve = func(id string) { reservedID.Store(id) } |
| + watch := ixWatchReservation(fx.srv.interactive) |
| snap := ixSnapshot(t, fx, ixHost) |
| ixSendOpen(t, ws, ixOpenArgv()) |
| if e := ixWantEnd(t, ws); e.Reason != interactive.EndRefused || e.Detail != runMovingMsg(ixHost) { |
| t.Fatalf("end %+v, want refused %q", e, runMovingMsg(ixHost)) |
| } |
| ixNothingWritten(t, fx, ixHost, snap) |
| - reserved, _ := reservedID.Load().(string) |
| + reserved := watch.waitReleased(t) |
| if reserved == "" || hubState(fx.srv.interactive, reserved) != "" || hubCount(fx.srv.interactive) != 0 { |
| t.Fatalf("the hub still holds %q (%q)", reserved, hubState(fx.srv.interactive, reserved)) |
| } |
| @@ -1183,8 +1213,7 @@ func TestAFailedGrantPutReleasesWithinOpenWait(t *testing.T) { |
| h := fx.srv.interactive |
| const wait = 500 * time.Millisecond |
| h.openWaitFor = wait |
| - var reservedID atomic.Value |
| - h.afterReserve = func(id string) { reservedID.Store(id) } |
| + watch := ixWatchReservation(h) |
| ws, err := ixDial(t, fx.ts.URL, fx.ixURL(ixHost), fx.alice) |
| if err != nil { |
| t.Fatal(err) |
| @@ -1198,11 +1227,9 @@ func TestAFailedGrantPutReleasesWithinOpenWait(t *testing.T) { |
| if e.Reason != interactive.EndRefused || e.Detail != "could not open the session. try again" { |
| t.Fatalf("end %+v, want refused with RFS-6-C37", e) |
| } |
| - id, _ := reservedID.Load().(string) |
| - deadline := time.Now().Add(time.Second) |
| - for (hubCount(h) != 0 || fx.srv.cutover.status().Pending != 0) && time.Now().Before(deadline) { |
| - time.Sleep(5 * time.Millisecond) |
| - } |
| + // The unit ended before the End was sent; the reservation is released |
| + // as the session's goroutine returns. |
| + id := watch.waitReleased(t) |
| if hubCount(h) != 0 || fx.srv.cutover.status().Pending != 0 { |
| t.Fatalf("after the refusal the hub holds %d and the gate counts %d units", hubCount(h), fx.srv.cutover.status().Pending) |
| } |
diff --git a/internal/console/interactivehub.go b/internal/console/interactivehub.go| index cc831a441..323450261 100644 |
| --- a/internal/console/interactivehub.go |
| +++ b/internal/console/interactivehub.go |
| @@ -72,11 +72,12 @@ type interactiveHub struct { |
| // |
| // afterChecks runs once a request has passed every refusal before the |
| // upgrade, just before it upgrades. afterReserve runs once an id is |
| - // reserved. afterAdmit runs after the record CAS lands, just before |
| + // reserved; afterRelease once a reserved id is released. afterAdmit runs after the record CAS lands, just before |
| // activate. pickupWindow and openWait, when not 0, replace |
| // interactive.PickupWindow and interactive.OpenWait. |
| afterChecks func() |
| afterReserve func(id string) |
| + afterRelease func(id string) |
| afterAdmit func(id string) |
| pickupWindow time.Duration |
| openWaitFor time.Duration |
| @@ -224,10 +225,15 @@ func (h *interactiveHub) activate(id string) bool { |
| // started, so nothing is marked ended. |
| func (h *interactiveHub) release(id string) { |
| h.mu.Lock() |
| - defer h.mu.Unlock() |
| - if sess, ok := h.byID[id]; ok && !sess.active { |
| + sess, ok := h.byID[id] |
| + released := ok && !sess.active |
| + if released { |
| delete(h.byID, id) |
| } |
| + h.mu.Unlock() |
| + if released && h.afterRelease != nil { |
| + h.afterRelease(id) |
| + } |
| } |
| // activeSession is the session id names when it is active, else nil: the |