| index b034608f1..c1a8c08f4 100644 |
| --- a/internal/host/systemapply.go |
| +++ b/internal/host/systemapply.go |
| @@ -327,6 +327,24 @@ func (a *systemApplier) ingressDrainBeforeSwap(ctx context.Context) { |
| } |
| } |
| |
| +// refusalsBeforeDrain runs, as a dry check just before the ingress drain |
| +// ask, the refusals the quiesce and the activation guard can still make |
| +// after it: the group maintenance permit (quiesce), the root protocol |
| +// check on the binary to be put in place, and the activation rule (moves |
| +// floor and hold rule) read again now. The guard applies them again under |
| +// its locks; this only makes a refusal there unlikely to follow a drain. |
| +// rootFloorDowngradeIdle, which the guard runs only inside its ledger |
| +// transaction, is not repeated here. |
| +func (a *systemApplier) refusalsBeforeDrain(version, running, binary string) error { |
| + if err := a.requireGroupMaintenance("apply", "rollback"); err != nil { |
| + return err |
| + } |
| + if err := a.rootProtocolAllowsBinary(binary); err != nil { |
| + return err |
| + } |
| + return a.activationRule(version, func() string { return running }) |
| +} |
| + |
| func (a *systemApplier) rootDir() string { return systemRootDir(a.optDir) } |
| func (a *systemApplier) stagingDir() string { return filepath.Join(a.rootDir(), "staging") } |
| func (a *systemApplier) lockPath() string { return filepath.Join(a.rootDir(), systemLockFile) } |
| @@ -698,6 +716,11 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea |
| // The release on disk, for the activation guard at the rename: read now, |
| // because reading it runs the binary and the guard holds locks. |
| running := a.onDiskBuild(ctx) |
| + // The activation guard's refusals, as a dry check, so the drain below |
| + // never precedes one of them (W6 spec §5.3). |
| + if err := a.refusalsBeforeDrain(target, running, staged); err != nil { |
| + return a.record(req, fmt.Errorf("%w: %v", errSystemRefused, err)) |
| + } |
| // Every refusal is behind us and this install restarts the edge: out of |
| // the load balancer first (W6 spec §5.3). Before the journal, so an |
| // apply killed during the drain leaves nothing to recover; the agent's |
| @@ -2116,6 +2139,11 @@ func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal, drai |
| return bootstrapPlan{}, err |
| } |
| if drain { |
| + // The guard's binary check and the quiesce's refusal too, before |
| + // the ask: a refusal never follows a drain (W6 spec §5.3). |
| + if err := a.refusalsBeforeDrain(prevVersion, running, prev); err != nil { |
| + return bootstrapPlan{}, err |
| + } |
| a.ingressDrainBeforeSwap(ctx) |
| } |
| // The same quiesce the install did: a root pass that is mid-flight |