Skip to content

domainmgr: bound the graceful stop wait for default-mode guests - #6453

Merged
eriknordmark merged 2 commits into
lf-edge:masterfrom
eriknordmark:bound-graceful-shutdown
Sep 7, 2026
Merged

eriknordmark merged 2 commits into
lf-edge:masterfrom
eriknordmark:bound-graceful-shutdown

Conversation

@eriknordmark

@eriknordmark eriknordmark commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #6440.

An application whose configuration leaves the virtualization mode unset gets
PV, the zero value of the mode enum. Only xen acts on that mode; under kvm or
kubevirt such a guest is an ordinary one which happens to have defaulted. Yet
deactivating it granted the ACPI poweroff request the entire ten-minute budget
before anything else was tried, because the PV case in doInactivate sets
doShutdown without lowering firstDelay from maxDelay the way HVM and
FML do. A guest which cannot service the request yet -- one still early in
boot, for instance -- therefore stayed reported as halting for that whole
period, holding its memory and any assigned devices, even though the steps
which follow would have freed it in seconds.

Such a guest now gets the same one-minute wait an HVM or FML guest already
gets, after which the stop escalates exactly as before. A xen PV guest keeps
the full budget:
there the mode names a real paravirtualized guest whose tools
are inherent, so a slow but cooperative shutdown is worth waiting out, and
shortening it would be a behaviour change for those guests that this PR does not
want to make.

The decision moves into shutdownBudget, which reports whether a poweroff
request is sent at all and how long it is given, so it can be exercised without
a running domainmgr.

PR dependencies

None. In particular this is independent of #6441 -- see below.

How to test and validate this PR

Covered by a unit test and an evetest test, both validated against un-fixed
code.

TestShutdownBudget covers all eight mode/hypervisor combinations. Reverting
the PV arm to return true, maxDelay fails exactly the two rows this PR
changes (firstDelay = 10m0s, want 1m0s) while the xen, HVM, FML,
NOHYPER and LEGACY rows still pass.

TestHaltAfterImmediateDeactivate, in evetest/tests/apps and registered in
TestAppsSuite, deploys a container application, waits until it is reported
RUNNING and deactivates it immediately -- nothing in between, because anything
which samples state first lets the guest become able to service the request and
the case stops being the one under test. Against an EVE image without this
change it fails:

shutdown_helpers_test.go:68: TEST FAILURE:
  application was not reported HALTED within 5m0s of being deactivated;
  a stop which does not escalate costs the whole 600s budget

and passes with it, reporting HALTED 1m37s after the deactivation.

The assertion is on elapsed time because the reported state sequence is
identical either way -- RUNNING, HALTING, HALTED -- and only the time spent
halting differs; there is nothing qualitative to assert on through the EVE API.
The 300s bound separates two hardcoded budgets an order of magnitude apart
rather than an amount of work, so it is not a stopwatch on a loaded host: the
prompt path measured 95-100s across ~90 runs under contention, against 636s and
701s for the two ways of losing the budget.

Measured end to end on EVE-kvm amd64 under evetest, deactivating a container
application in the same second it first reports RUNNING, which is the #6440
trigger. Three EVE images off one common base, differing only in the fix, with
every run's achieved RUNNING->deactivate gap confirmed to be 0s:

build deactivate -> HALTED
base 637 / 636 / 637 s
base + this PR 98 / 95 / 96 s
base + this PR + #6441 99 / 97 / 99 s

Soaked for 8 hours on the middle build: 85 runs, all at a 0s gap, 95-100s,
no outliers
, bookended by runs of the un-fixed build which still produced
636s and 637s -- so "never stalled" reflects the change and not a trigger which
quietly stopped firing.

The third row is why this PR does not depend on #6441: with the graceful wait
bounded, the guest is ACPI-capable by the time the request is re-sent, so
making the escalation terminate the domain saves nothing here. #6441 is
needed for a different failure, #6452, where the guest never becomes capable at
all -- there this PR is the one that changes nothing. The two are complementary
and neither subsumes the other.

Changelog notes

An application which is stopped very shortly after it starts is no longer held
for ten minutes before it is reported as stopped.

PR Backports

The PV case has left firstDelay at maxDelay since the switch was written,
so every stable branch carries it.

Checklist

  • I've provided a proper description
  • I've added the proper documentation -- no documented behaviour changes;
    the budgets are internal to doInactivate.
  • I've tested my PR on amd64 device -- the measurements above.
  • I've tested my PR on arm64 device -- not tested; the change is
    architecture independent.
  • I've written the test verification instructions
  • I've set the proper labels to this PR

@eriknordmark eriknordmark added next-13.4.x-rc PR must be present in the next 13.4.x patch release next-14.5.x-rc PR must be present in the next 14.5.x patch release next-16.0.x-rc PR must be present in the next 16.0.x patch release next-17.0.x-rc PR must be present in the next 17.0.x-lts release stable Should be backported to stable release(s) labels Sep 2, 2026
@europaul

europaul commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

/rerun red

1 similar comment
@europaul

europaul commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

/rerun red

@eriknordmark eriknordmark removed next-13.4.x-rc PR must be present in the next 13.4.x patch release next-14.5.x-rc PR must be present in the next 14.5.x patch release next-16.0.x-rc PR must be present in the next 16.0.x patch release next-17.0.x-rc PR must be present in the next 17.0.x-lts release labels Sep 2, 2026
@eriknordmark
eriknordmark requested a review from rene September 7, 2026 08:28
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.01%. Comparing base (4cce2f0) to head (9e65bea).
⚠️ Report is 49 commits behind head on master.

Files with missing lines Patch % Lines
pkg/pillar/cmd/domainmgr/domainmgr.go 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6453      +/-   ##
==========================================
+ Coverage   25.67%   26.01%   +0.33%     
==========================================
  Files         509      519      +10     
  Lines       93304    95023    +1719     
==========================================
+ Hits        23959    24716     +757     
- Misses      67496    68273     +777     
- Partials     1849     2034     +185     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@milan-zededa

Copy link
Copy Markdown
Contributor

@eriknordmark Some merge conflict on this PR to address, otherwise LGTM.

eriknordmark and others added 2 commits September 7, 2026 16:38
An application whose configuration leaves the virtualization mode unset gets
PV, the zero value of the mode enum. Only xen acts on that mode; under kvm or
kubevirt such a guest is an ordinary one that happens to have defaulted, yet
deactivating it granted the ACPI poweroff request the entire ten-minute budget
before anything else was tried. A guest that cannot service the request yet,
one still early in boot for instance, therefore stayed reported as halting for
that whole period, holding its memory and any assigned devices, even though the
forced stop and the delete that follow would have freed it in seconds.

Such a guest now gets the same one-minute wait an HVM or FML guest already
gets, after which the stop escalates as before. A xen PV guest keeps the full
budget: there the mode names a real paravirtualized guest whose tools are
inherent, so a slow but cooperative shutdown is worth waiting out.

The decision moves into shutdownBudget, which reports whether a poweroff
request is sent at all and how long it is given, so it can be exercised
directly.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Deactivating an application in the same second it first reports RUNNING catches
a guest which cannot service the ACPI poweroff request yet, so the stop only
completes once it escalates. The budget before that escalation depends on the
virtualization mode, and an application whose configuration leaves the mode
unset gets the zero value, which is the case this covers.

The assertion is on how long the application takes to be reported HALTED,
because the reported state sequence is the same either way -- only the time
spent halting differs. The bound separates two hardcoded budgets an order of
magnitude apart rather than an amount of work, so a loaded host moves both ends
a little and crosses neither.

Signed-off-by: eriknordmark <erik@zededa.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stable Should be backported to stable release(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kvm: forced domain stop is the same ACPI request as a graceful one

3 participants