Skip to content

[14.5-stable] remove stale dir of deleted domain - #6563

Merged
eriknordmark merged 1 commit into
lf-edge:14.5-stablefrom
europaul:fix-14.5-kvm-state-dir-leak
Sep 18, 2026
Merged

eriknordmark merged 1 commit into
lf-edge:14.5-stablefrom
europaul:fix-14.5-kvm-state-dir-leak

Conversation

@europaul

@europaul europaul commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

KvmContext.Delete returns as soon as the QMP quit command fails and never reaches the os.RemoveAll of /run/hypervisor/kvm/<domain>. The quit fails precisely when qemu is already gone: a qemu that crashed (e.g. on a fatal signal) does not unlink its sockets, so the executor socket passes the os.Stat, the connect fails after the retry loop, and the state directory with its stale pid and listener.qmp files survives for the lifetime of the device.

That surviving listener.qmp is what keeps the old domain's qmpEventHandler alive on this branch: its liveness check is an os.Stat of that very file, so after a crash it spins on the closed event channel logging Unhandled event: with an empty name a few hundred times a second per dead domain. A 13.4.3-lts device seen with two crashed generations had two such goroutines running for a week.

Why not a cherry-pick from master

Master fixed this as a side effect of #6120 (38fc3e75c, "promptly reap powered-off kvm domains"), which dropped the early return while adding a SIGKILL backstop; #6441 (dbb5dc5e5) then refactored that into terminateQemu. Both are on 17.0-stable (#6120 as 0a034d02c, #6441 as #6490).

This PR is the correctness slice only: log the quit failure, always remove the directory, return the quit error (joined with a removal error, if any). If the outstanding #6441 backports to these branches are done later, they will meet a small conflict in Delete() — take #6441's version.

This is a stable-only fix — there is nothing to backport from master. Sibling PRs: #6562 #6564

How to test and validate this PR

  1. Deploy a VM app; note its domain name <uuid>.<ver>.1 under /run/hypervisor/kvm/.
  2. Kill qemu hard: kill -SEGV $(cat /run/hypervisor/kvm/<domain>/pid).
  3. Wait for domainmgr's verifyStatus to mark the app BROKEN (≤ 1 min).
  4. ls /run/hypervisor/kvm/ — the dead domain's directory is gone. Before this fix it stays, and logread fills with qmpEventHandler: Unhandled event: from QMP socket: .../<domain>/listener.qmp.
  5. Restart the app; the new domain starts normally.

Changelog notes

After a VM's QEMU process crashes, its runtime state directory is now cleaned up; previously it leaked and caused a continuous stream of Unhandled event warnings in the device log.

Checklist

  • I've provided a proper description

  • I've added the proper documentation — not applicable

  • I've tested my PR on amd64 device — reproduction analysed from a customer collect-info; not yet re-run on a lab device

  • I've tested my PR on arm64 device

  • I've written the test verification instructions

  • I've set the proper labels to this PR

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

🤖 Generated with Claude Code

KvmContext.Delete returned as soon as the QMP quit command failed and
never reached the os.RemoveAll of /run/hypervisor/kvm/<domain>. The
quit fails precisely when qemu is already gone: a qemu that crashed
(e.g. on a fatal signal) does not unlink its sockets, so the executor
socket passes the os.Stat, the connect fails after the retry loop, and
the state directory with its stale pid and listener.qmp files survives
for the lifetime of the device.

That surviving listener.qmp is what keeps the old domain's
qmpEventHandler alive on 13.4.x: its liveness check is an os.Stat of
that very file, so after the crash it spins on the closed event channel
logging 'Unhandled event:' with an empty name a few hundred times a
second per dead domain. A device seen with two crashed generations had
two such goroutines running for a week.

Master no longer has this path since dbb5dc5 replaced the quit with
terminateQemu, which removes the directory unconditionally. Mirror that
here: log the quit failure, always remove the directory, and return the
quit error afterwards so callers still see it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Paul Gaiduk <paulg@zededa.com>
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.62%. Comparing base (272ffae) to head (4724590).
⚠️ Report is 214 commits behind head on 14.5-stable.

Additional details and impacted files
@@               Coverage Diff               @@
##           14.5-stable    #6563      +/-   ##
===============================================
+ Coverage        24.97%   32.62%   +7.64%     
===============================================
  Files                8        9       +1     
  Lines             1185     1122      -63     
===============================================
+ Hits               296      366      +70     
+ Misses             820      675     -145     
- Partials            69       81      +12     

☔ 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.

@rene

rene commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

@europaul Please, fix PR title

@europaul europaul changed the title hypervisor: remove the kvm state dir even when the QMP quit fails [14.5-stable] remove stale dir of deleted domain Sep 17, 2026

@eriknordmark eriknordmark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eriknordmark
eriknordmark merged commit af50a9b into lf-edge:14.5-stable Sep 18, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants