all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH qemu-server v2] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds
@ 2026-02-10 11:15 Dominik Csapak
  2026-02-12 20:33 ` Benjamin McGuire
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Dominik Csapak @ 2026-02-10 11:15 UTC (permalink / raw)
  To: pve-devel

When qmeventd detects a vm exiting, it starts 'qm cleanup' to cleanup
files, executing hookscripts, etc.

Since the vm process exits is sometimes not instant, wait up to 30
seconds here to start the cleanup process instead of immediately
aborting if the pid still exits. This prevented executing the hookscript
on the 'post-stop' phase.

This can be easily reproduced by e.g. passing through a usb device,
which delays the qemu process exit for a few seconds.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v1:
* use correct while condition (time() is always >= $starttime)

original comment:

The 30 second timeout was arbitrarily chosen, but we could probably
start with something smaller, like 10 seconds? Could be adapted on
applying though.

In my (short) tests the usb passthrough part only adds a single second,
but i can imagine different devices on other systems could block it for
much longer.

 src/PVE/CLI/qm.pm | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
index bdae9641..16875ed2 100755
--- a/src/PVE/CLI/qm.pm
+++ b/src/PVE/CLI/qm.pm
@@ -1101,8 +1101,19 @@ __PACKAGE__->register_method({
             60,
             sub {
                 my $conf = PVE::QemuConfig->load_config($vmid);
+
+                # wait for some timeout until vm process exits, since this might not be instant
+                my $timeout = 30;
+                my $starttime = time();
                 my $pid = PVE::QemuServer::check_running($vmid);
-                die "vm still running\n" if $pid;
+                warn "vm still running - waiting up to $timeout seconds\n" if $pid;
+
+                while ($pid && (time() - $starttime) < $timeout) {
+                    sleep(1);
+                    $pid = PVE::QemuServer::check_running($vmid);
+                }
+
+                die "vm still running - aborting cleanup\n" if $pid;
 
                 # Rollback already does cleanup when preparing and afterwards temporarily drops the
                 # lock on the configuration file to rollback the volumes. Deactivating volumes here
-- 
2.47.3





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-02-20 14:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-10 11:15 [PATCH qemu-server v2] fix #7119: qm cleanup: wait for process exiting for up to 30 seconds Dominik Csapak
2026-02-12 20:33 ` Benjamin McGuire
2026-02-13 11:40 ` Fabian Grünbichler
2026-02-13 12:14 ` Fiona Ebner
2026-02-13 12:20   ` Fabian Grünbichler
2026-02-13 13:16     ` Fiona Ebner
2026-02-16  8:42       ` Fabian Grünbichler
2026-02-16  9:15         ` Fiona Ebner
2026-02-19 10:15           ` Dominik Csapak
2026-02-19 13:27             ` Fiona Ebner
2026-02-20  9:36               ` Dominik Csapak
2026-02-20 14:30                 ` Fiona Ebner
2026-02-20 14:51                   ` Dominik Csapak
2026-02-13 12:22   ` Dominik Csapak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal