From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3193993603 for ; Mon, 20 Feb 2023 11:09:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E8B092529E for ; Mon, 20 Feb 2023 11:08:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 20 Feb 2023 11:08:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 75CA447C51 for ; Mon, 20 Feb 2023 11:08:29 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 20 Feb 2023 11:08:28 +0100 Message-Id: <20230220100828.3416873-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.062 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC PATCH common] RESTEnvironment: better SIGCHLD handling in AnyEvent event loop X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Feb 2023 10:09:01 -0000 when we're in an API server that uses AnyEvent, we must postpone the worker_reaper, since it calls 'active_workers' which might already be called and then we're inside the lock twice (flocks are per process for us, see PVE::Tools::lock_file) This resulted in an error like this: close (rename) atomic file '/var/log/pve/tasks/active' failed: No such file or directory We use the fact that only 'pub' and 'priv' RESTEnvironment types are an api server with anyevent. For other types we call it like before. Signed-off-by: Dominik Csapak --- Not super happy about the coupling between the RESTEnvironment and AnyEvent. We could try to just save the worker_reaper in 'self' and let the users of the env decide when to call it, but that would be more involved. OTOH, we already do some anyevent specific things in PVE::Daemon (without depending on the AnyEvent package though)... Also i did not find a way to dynamically find out if we're in an AnyEvent loop... debian/control | 1 + src/PVE/RESTEnvironment.pm | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 232a0e4..1c75985 100644 --- a/debian/control +++ b/debian/control @@ -3,6 +3,7 @@ Section: perl Priority: optional Maintainer: Proxmox Support Team Build-Depends: debhelper (>= 12~), + libanyevent-perl, libclone-perl, libdevel-cycle-perl, libfilesys-df-perl, diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index bf89c12..c258b1e 100644 --- a/src/PVE/RESTEnvironment.pm +++ b/src/PVE/RESTEnvironment.pm @@ -14,6 +14,7 @@ use IO::File; use IO::Handle; use IO::Select; use POSIX qw(:sys_wait_h EINTR); +use AnyEvent; use PVE::Exception qw(raise raise_perm_exc); use PVE::INotify; @@ -111,7 +112,17 @@ sub init { die "unknown environment type" if !$type || $type !~ m/^(cli|pub|priv|ha)$/; - $SIG{CHLD} = $worker_reaper; + 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 + # might interfere with running api calls + if ($has_anyevent) { + AnyEvent::postpone { $worker_reaper->() }; + } else { + $worker_reaper->(); + } + }; # environment types # cli ... command started fron command line -- 2.30.2