[pve-devel] [PATCH common] fix #4615: RESTEnvironment: correctly detect AnyEvent in SIGCHLD handler

Dominik Csapak d.csapak at proxmox.com
Mon Mar 27 10:26:32 CEST 2023


we assumed that the 'priv' and 'pub' RESTEnvironment types always
contained an AnyEvent eventloop, but this is actually not the case
in pvestatd and pvescheduler.

When we wrongly determined that, it depended on the used model that AnyEvent
used (and autodetected) if it worked or not. With AnyEvent::Impl::Perl it did
not make problems (and 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")
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/RESTEnvironment.pm | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index c258b1e..89def38 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -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->();
-- 
2.30.2






More information about the pve-devel mailing list