]> git.proxmox.com Git - pve-common.git/commitdiff
fix #4615: REST environment: improve AnyEvent detectíon in child cleanup
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 27 Mar 2023 08:26:32 +0000 (10:26 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 27 Mar 2023 08:35:53 +0000 (10:35 +0200)
I assumed that the 'priv' and 'pub' RESTEnvironment types always
contained an AnyEvent eventloop, but this is actually not the case in
pvestatd and pvescheduler.

But it depended on the used model that AnyEvent used (and auto
detected) if this wrong assumption worked or not. With the
AnyEvent::Impl::Perl there weren't any problems and it seemingly
worked by accident, but when using AnyEvent::Impl::EV (which is
autodetected and used when libev-perl is installed) it interfered
with our SIG_CHLD handlers and only ever called them once. (Not clear
why this happens, maybe because AnyEvent is not setup correctly).

This patch uses $AnyEvent::MODEL as a detection instead since this is
`undef` until the first AnyEvent watcher is created, which should be
only the case where we really use AnyEvent, such as pveproxy and
pvedaemon.

Fixes: 6870afa ("RESTEnvironment: better SIGCHLD handling in AnyEvent event loop")
Link: https://lists.proxmox.com/pipermail/pve-devel/2023-March/056057.html
Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/RESTEnvironment.pm

index c258b1e16aaf48e1ea9f8bed220caf54b540c404..89def38354b061e606ed6f60075dae396bb0e596 100644 (file)
@@ -112,12 +112,10 @@ sub init {
     die "unknown environment type"
        if !$type || $type !~ m/^(cli|pub|priv|ha)$/;
 
-    my $has_anyevent = $type eq 'pub' || $type eq 'priv';
-
     $SIG{CHLD} = sub {
-       # when we're in an api server, we have to postpone the call to worker_reaper, otherwise it
+       # when we're using AnyEvent, we have to postpone the call to worker_reaper, otherwise it
        # might interfere with running api calls
-       if ($has_anyevent) {
+       if (defined($AnyEvent::MODEL)) {
            AnyEvent::postpone { $worker_reaper->() };
        } else {
            $worker_reaper->();