From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 51D5A1FF0AA for ; Tue, 20 Oct 2026 16:12:36 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id E4711216FA; Tue, 20 Oct 2026 16:12:33 +0200 (CEST) From: Kefu Chai To: pve-devel@lists.proxmox.com Subject: [PATCH librados2-perl] do not shut down the handle twice if a signal arrives at exit Date: Tue, 20 Oct 2026 22:12:23 +0800 Message-ID: <20261020141223.2814127-1-k.chai@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792505549658 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.307 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 2D6GEXWDSUJOI5OGY3D6R3G5ZEMX4IXO X-Message-ID-Hash: 2D6GEXWDSUJOI5OGY3D6R3G5ZEMX4IXO X-MailFrom: k.chai@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: When a pveceph worker finishes, the CLI sends SIGTERM to its process group, which includes the pverados child. That child is often already shutting down the handle after seeing EOF, so the handler then calls rados_shutdown() on the freed handle and the child segfaults. The handlers outlived the eval anyway, as the 'local' only covered $SIG{HUP}. So ignore the signals before shutting down, and install the handlers first thing in the child. Signed-off-by: Kefu Chai --- PVE/RADOS.pm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/PVE/RADOS.pm b/PVE/RADOS.pm index 5a79235..deb4912 100644 --- a/PVE/RADOS.pm +++ b/PVE/RADOS.pm @@ -200,6 +200,17 @@ sub new { } else { # child $0 = 'pverados'; + my @signals = qw(HUP INT QUIT TERM); + + # ignore signals from here on, the handler must not shut down a freed handle + my $shutdown = sub { + @SIG{@signals} = ('IGNORE') x @signals; + pve_rados_shutdown($self->{conn}) if $self->{conn}; + }; + + # override signal handlers inherited from the parent + @SIG{@signals} = (sub { $shutdown->(); POSIX::_exit(1); }) x @signals; + eval { PVE::INotify::inotify_close(); @@ -207,12 +218,6 @@ sub new { &$atfork(); } - # override signal handlers inherited from the parent - local $SIG{HUP} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub { - pve_rados_shutdown($self->{conn}) if $self->{conn}; - POSIX::_exit(1); - }; - # fixme: timeout? close $child; @@ -222,7 +227,7 @@ sub new { my $err = $@; warn $err if $err; - pve_rados_shutdown($self->{conn}) if $self->{conn}; + $shutdown->(); POSIX::_exit($err ? 1 : 0); } -- 2.47.3