region HA: a drain does not wait for a proven-departed member
On dev IE (2026-11-17) a dead member's edges record stayed published, the verb listed it, and the next drain asked it for two minutes and failed. The drain driver now skips a listed or folded peer that is a group ref whose departure this box has enrolled (Controller.PeerDeparted, the rule DR-5's provenDeparted already used: termination proven, one iid per g- ref). The report lists such peers under "departed". Fixed refs and unproven peers keep today's wait and named failure. Witness: the 11-17 sequence on the DR-5 rig with the trashed host; the drain succeeds while A's record is still published, A's departure then retires it within the DR-5 bound, and a later drain acks the live peer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+202
−21
internal/host/agent.go+4 −0internal/host/hadepartures_metrics.go+6 −0internal/host/hadepartures_scan.go+17 −5internal/host/hadrain.go+41 −16internal/host/hadrain_departed_test.go+134 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 838c77eab..3283fd277 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -1330,6 +1330,10 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| // only: the drain verbs are theirs. |
| if admission != nil && admission.group { |
| driver.group = newDrainDriver(svc, e, boxDrain, groupStartFence.read) |
| + // #1192: a proven-departed member is not waited on. |
| + // The departure controller arms later, behind |
| + // admission; read it as armed at each ask. |
| + driver.group.departed = armedPeerDeparted |
| } |
| setDutyView = svc.SetDutyView |
| } |
diff --git a/internal/host/hadepartures_metrics.go b/internal/host/hadepartures_metrics.go| index 40e123484..040229a50 100644 |
| --- a/internal/host/hadepartures_metrics.go |
| +++ b/internal/host/hadepartures_metrics.go |
| @@ -71,3 +71,9 @@ func sampleDepartures() *metrics.DepartureSample { |
| s, _ := c.Metrics(ctx) |
| return &s |
| } |
| + |
| +// armedPeerDeparted is the armed departure controller's PeerDeparted, false |
| +// while none is armed (the drain driver's departed, #1192). |
| +func armedPeerDeparted(ctx context.Context, ref string) bool { |
| + return metricsDepartures.Load().PeerDeparted(ctx, ref) |
| +} |
diff --git a/internal/host/hadepartures_scan.go b/internal/host/hadepartures_scan.go| index ff2ca817d..76d298ede 100644 |
| --- a/internal/host/hadepartures_scan.go |
| +++ b/internal/host/hadepartures_scan.go |
| @@ -6,6 +6,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "fmt" |
| + "github.com/carlosframework/platform/internal/boxid" |
| "os" |
| "path" |
| "strconv" |
| @@ -514,15 +515,26 @@ func (c *Controller) provenDeparted(ctx context.Context, d registry.HADeparture, |
| memo[ref] = ref == groupReferenceOf(d.Box.Account, d.Box.InstanceID) |
| return memo[ref] |
| } |
| - o, ok, err := c.cfg.Identities.Resolve(ctx, ref, "") |
| - if err != nil || !ok || !o.Known || o.PlacementNull || o.Box.Ref != ref || ref != groupReferenceOf(o.Box.Account, o.Box.InstanceID) { |
| + memo[ref] = c.PeerDeparted(ctx, ref) |
| + return memo[ref] |
| +} |
| + |
| +// PeerDeparted is provenDeparted's rule for any other box, and the drain's |
| +// (#1192): ref is a group reference, bound to its one account and instance |
| +// by a verified identity, whose departure this box's journal holds (any |
| +// phase). Enrollment requires termination proof, so a true answer means |
| +// the instance is terminated and nothing will publish under ref again. |
| +// Any failure, an unknown ref, a fixed ref or this box answers false. |
| +func (c *Controller) PeerDeparted(ctx context.Context, ref string) bool { |
| + if c == nil || !boxid.ValidBox(ref) || ref == c.cfg.Self.Ref { |
| return false |
| } |
| - if _, err = c.cfg.Registry.Departure(ctx, departureID(c.cfg.DeploymentBucket, o.Box)); err != nil { |
| + o, ok, err := c.cfg.Identities.Resolve(ctx, ref, "") |
| + if err != nil || !ok || !o.Known || o.PlacementNull || o.Box.Ref != ref || ref != groupReferenceOf(o.Box.Account, o.Box.InstanceID) { |
| return false |
| } |
| - memo[ref] = true |
| - return true |
| + _, err = c.cfg.Registry.Departure(ctx, departureID(c.cfg.DeploymentBucket, o.Box)) |
| + return err == nil |
| } |
| type departureLockListing struct { |
diff --git a/internal/host/hadrain.go b/internal/host/hadrain.go| index 38247d378..2cb6b9e63 100644 |
| --- a/internal/host/hadrain.go |
| +++ b/internal/host/hadrain.go |
| @@ -144,17 +144,20 @@ type drainReport struct { |
| Reasons []string `json:"reasons"` |
| // Fence is the start fence's transaction as the move step read it, |
| // at its start and again at its end. |
| - Fence string `json:"fence"` |
| - StartedAt time.Time `json:"started_at"` |
| - FinishedAt *time.Time `json:"finished_at"` |
| - Acked []string `json:"acked"` |
| - Moved []drainMoved `json:"moved"` |
| - Released []drainLeft `json:"released"` |
| - Unclean []string `json:"unclean"` |
| - Left []drainLeft `json:"left"` |
| - Holds drainHolds `json:"holds"` |
| - Closed int `json:"connections_closed_at_bound"` |
| - Quiet drainQuietOut `json:"quiet"` |
| + Fence string `json:"fence"` |
| + StartedAt time.Time `json:"started_at"` |
| + FinishedAt *time.Time `json:"finished_at"` |
| + Acked []string `json:"acked"` |
| + // Departed is the listed peers not waited for: group members whose |
| + // departure this box has enrolled, termination proven (#1192). |
| + Departed []string `json:"departed,omitempty"` |
| + Moved []drainMoved `json:"moved"` |
| + Released []drainLeft `json:"released"` |
| + Unclean []string `json:"unclean"` |
| + Left []drainLeft `json:"left"` |
| + Holds drainHolds `json:"holds"` |
| + Closed int `json:"connections_closed_at_bound"` |
| + Quiet drainQuietOut `json:"quiet"` |
| } |
| // drainMoved is one host moved: its confirmed holder and lock generation. |
| @@ -201,6 +204,10 @@ type drainDriver struct { |
| // and logf their log: seams for tests. |
| quietTick func() (<-chan time.Time, func()) |
| logf func(format string, args ...any) |
| + // departed reports a peer that is a group member whose departure this |
| + // box has enrolled (Controller.PeerDeparted): terminated, proven, and |
| + // never coming back under that reference. Nil waits for every peer. |
| + departed func(ctx context.Context, ref string) bool |
| mu sync.Mutex |
| // txn is the drain transaction this agent is in, "" for none. |
| @@ -353,6 +360,7 @@ func (d *drainDriver) snapshot() *drainReport { |
| c := *d.report |
| c.Reasons = append([]string(nil), c.Reasons...) |
| c.Acked = append([]string(nil), c.Acked...) |
| + c.Departed = append([]string(nil), c.Departed...) |
| c.Moved = append([]drainMoved(nil), c.Moved...) |
| c.Released = append([]drainLeft(nil), c.Released...) |
| c.Unclean = append([]string(nil), c.Unclean...) |
| @@ -591,6 +599,10 @@ func (d *drainDriver) publishAndAck(ctx context.Context, txn, phase string, rep |
| // their answers back on a channel. |
| seen := map[string]bool{} |
| why := map[string]string{} |
| + // gone: peers proven departed (#1192). A dead member cannot answer, |
| + // and its edges record stays published until its departure finishes, |
| + // so waiting for it only fails the drain at the bound. |
| + gone := map[string]bool{} |
| type answer struct { |
| peer string |
| ok bool |
| @@ -605,13 +617,26 @@ func (d *drainDriver) publishAndAck(ctx context.Context, txn, phase string, rep |
| } |
| var pending []string |
| for _, p := range peers { |
| - if !seen[p] { |
| + if !seen[p] && !gone[p] && d.departed != nil && d.departed(actx, p) { |
| + gone[p] = true |
| + d.logf("ha-drain: %s is a departed group member (termination proven); its acknowledgement is not awaited", p) |
| + } |
| + if !seen[p] && !gone[p] { |
| pending = append(pending, p) |
| } |
| } |
| if len(pending) == 0 { |
| - sort.Strings(peers) |
| - d.note(func() { rep.Acked = append([]string(nil), peers...) }) |
| + var acked, departed []string |
| + for _, p := range peers { |
| + if gone[p] && !seen[p] { |
| + departed = append(departed, p) |
| + } else { |
| + acked = append(acked, p) |
| + } |
| + } |
| + sort.Strings(acked) |
| + sort.Strings(departed) |
| + d.note(func() { rep.Acked, rep.Departed = acked, departed }) |
| return nil |
| } |
| answers := make(chan answer, len(pending)) |
| @@ -634,11 +659,11 @@ func (d *drainDriver) publishAndAck(ctx context.Context, txn, phase string, rep |
| why[a.peer] = "not seen yet" |
| } |
| } |
| - if allSeen(peers, seen) { |
| + if allSeen(pending, seen) { |
| continue |
| } |
| var missing []string |
| - for _, p := range peers { |
| + for _, p := range pending { |
| if !seen[p] { |
| missing = append(missing, p+" ("+why[p]+")") |
| } |
diff --git a/internal/host/hadrain_departed_test.go b/internal/host/hadrain_departed_test.go| new file mode 100644 |
| index 000000000..f58ed2b15 |
| --- /dev/null |
| +++ b/internal/host/hadrain_departed_test.go |
| @@ -0,0 +1,134 @@ |
| +package host |
| + |
| +// #1192: a drain does not wait for a peer that is a proven-departed group |
| +// member. On dev IE (2026-11-17) the dead member g-03152630's edges record |
| +// stayed published, the verb listed it, and the drain of the next member |
| +// asked it for 2 minutes and failed ("the draining state was not |
| +// acknowledged by g-03152630...: context deadline exceeded"). |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "slices" |
| + "strings" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestDrainSkipsProvenDepartedPeer(t *testing.T) { |
| + defer shorten(&drainAckBound, 200*time.Millisecond)() |
| + defer shorten(&drainAckEvery, 20*time.Millisecond)() |
| + act, ed, marks := healthyDrain() |
| + ed.peers = []string{"b", "c", "g-dead"} |
| + ed.ack = func(peer string) (bool, error) { |
| + if peer == "g-dead" { |
| + return false, context.DeadlineExceeded |
| + } |
| + return true, nil |
| + } |
| + d := newDrainDriver(act, ed, marks, fenceOf("t1")) |
| + d.departed = func(_ context.Context, ref string) bool { return ref == "g-dead" } |
| + rep := runDrainListed(t, d, "t1", []string{"b", "g-dead"}) |
| + if rep.Result != "ok" { |
| + t.Fatalf("report %+v", rep) |
| + } |
| + if !slices.Equal(rep.Departed, []string{"g-dead"}) || slices.Contains(rep.Acked, "g-dead") || !slices.Contains(rep.Acked, "b") || !slices.Contains(rep.Acked, "c") { |
| + t.Fatalf("acked %v departed %v", rep.Acked, rep.Departed) |
| + } |
| + if n := ed.askCount("g-dead draining") + ed.askCount("g-dead drained"); n != 0 { |
| + t.Fatalf("a proven-departed peer was asked %d times", n) |
| + } |
| +} |
| + |
| +// A peer proven departed only while the drain waits (its departure enrolls |
| +// late) stops being waited for at once; one never proven still fails the |
| +// drain at the bound, named, as before. |
| +func TestDrainDepartedPeerProvenLateAndNever(t *testing.T) { |
| + defer shorten(&drainAckBound, 300*time.Millisecond)() |
| + defer shorten(&drainAckEvery, 20*time.Millisecond)() |
| + act, ed, marks := healthyDrain() |
| + ed.ack = func(peer string) (bool, error) { |
| + if peer == "c" { |
| + return false, errors.New("dial refused") |
| + } |
| + return true, nil |
| + } |
| + d := newDrainDriver(act, ed, marks, fenceOf("t1")) |
| + d.departed = func(_ context.Context, ref string) bool { return ref == "c" && ed.askCount("c draining") >= 2 } |
| + if rep := runDrain(t, d, "t1"); rep.Result != "ok" || !slices.Equal(rep.Departed, []string{"c"}) { |
| + t.Fatalf("late proof: report %+v", rep) |
| + } |
| + |
| + act, ed, marks = healthyDrain() |
| + ed.ack = func(peer string) (bool, error) { |
| + if peer == "c" { |
| + return false, errors.New("dial refused") |
| + } |
| + return true, nil |
| + } |
| + d = newDrainDriver(act, ed, marks, fenceOf("t1")) |
| + d.departed = func(context.Context, string) bool { return false } |
| + if rep := runDrain(t, d, "t1"); rep.Result != "failed" || !strings.Contains(strings.Join(rep.Reasons, ";"), "c (dial refused)") || len(rep.Departed) != 0 { |
| + t.Fatalf("never proven: report %+v", rep) |
| + } |
| +} |
| + |
| +// The 11-17 sequence on the production departure wiring (the DR-5 rig with |
| +// the trashed g6x host): member A terminated, its departure enrolled; a |
| +// drain on this box that lists A does not wait for it; the departure then |
| +// finishes within the DR-5 bound and retires A's edges record. PeerDeparted |
| +// answers only for the proven group member: never for a live peer, an |
| +// unknown ref, this box, or a fixed ref (whose name a replacement reuses). |
| +func TestDrainAfterLostMember1192(t *testing.T) { |
| + defer shorten(&drainAckBound, 300*time.Millisecond)() |
| + defer shorten(&drainAckEvery, 20*time.Millisecond)() |
| + // The fixed-ref case on its own rig: its serving replacement blocks A. |
| + fx := newDR5Rig(t, dr5Options{fixedPeer: true}) |
| + if fx.c.PeerDeparted(t.Context(), "fixedha") { |
| + t.Fatal("PeerDeparted(fixed ref) = true") |
| + } |
| + |
| + x := newDR5Rig(t, dr5Options{}) |
| + withTrashedHost(t, x) |
| + ctx := t.Context() |
| + |
| + if !x.c.PeerDeparted(ctx, x.dead.Ref) || !x.c.PeerDeparted(ctx, x.b.Ref) { |
| + t.Fatal("the terminated members are not proven departed") |
| + } |
| + for _, ref := range []string{x.peer.Ref, x.a.Self.Ref, "g-00000000000000000000", "not a ref"} { |
| + if x.c.PeerDeparted(ctx, ref) { |
| + t.Fatalf("PeerDeparted(%q) = true", ref) |
| + } |
| + } |
| + |
| + drain := func(listed []string) *drainReport { |
| + act, ed, marks := healthyDrain() |
| + ed.peers = append([]string{x.peer.Ref}, listed...) |
| + ed.ack = func(peer string) (bool, error) { |
| + if peer == x.peer.Ref { |
| + return true, nil |
| + } |
| + return false, context.DeadlineExceeded |
| + } |
| + d := newDrainDriver(act, ed, marks, fenceOf("t1")) |
| + d.departed = x.c.PeerDeparted |
| + return runDrainListed(t, d, "t1", append([]string{x.peer.Ref}, listed...)) |
| + } |
| + // Before the departure finishes: A is still listed and does not answer. |
| + if x.gone(t, x.edgesKey) { |
| + t.Fatal("A's edges record is already gone; the witness proves nothing") |
| + } |
| + rep := drain([]string{x.dead.Ref}) |
| + if rep.Result != "ok" || !slices.Equal(rep.Departed, []string{x.dead.Ref}) { |
| + t.Fatalf("drain with A listed: %+v", rep) |
| + } |
| + |
| + doneA, _ := x.run(t, 5*time.Minute, nil) |
| + if doneA == 0 || doneA > dr5Bound || !x.gone(t, x.edgesKey) { |
| + t.Fatalf("A's departure: done at T+%s, edges gone %v; logs %q", doneA, x.gone(t, x.edgesKey), x.logs) |
| + } |
| + // After: the verb no longer lists A, and the drain acks the live peer. |
| + if rep = drain(nil); rep.Result != "ok" || len(rep.Departed) != 0 { |
| + t.Fatalf("drain after the departure: %+v", rep) |
| + } |
| +} |