From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 648D41F47A for ; Wed, 4 Oct 2023 08:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696409459; bh=+5Tf+nxtLx8K2WNThg4j/VVdPP5GoA+GC++oenQ9HzA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oNdXWNsp7zz4LG7CgOEwcQ1T3lI3GCXwVlsEDavYO1Jvk7yzP4mgHlgV2POYsfYXC 8JJGJJqLUQgM0ODvkhTxT/ys79YSfS2koM5x1hGGYO1iV5FouDY3N8G8f3TIPmT6EZ SLkY8mPVM+SjgnpBt6QEP4gLdaikdMnpVqT4/vzI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] ds: Reset: replace Poller object early Date: Wed, 4 Oct 2023 08:50:56 +0000 Message-ID: <20231004085059.2115839-2-e@80x24.org> In-Reply-To: <20231004085059.2115839-1-e@80x24.org> References: <20231004085059.2115839-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Process shutdown can be chaotic and unpredictable. Try to make it more predictable by ensuring any PublicInbox::Select object can't hold references to any objects. This should fix the following error I saw in syslog during a deploy: Can't call method "FILENO" on an undefined value at .../PublicInbox/Select.pm line 34 during global destruction. Replacing $Poller with PublicInbox::Select (instead of undef-ing it) means we can avoid adding branches to ->epwait and ->close before calls to ->ep_mod and ->ep_del, respectively. --- lib/PublicInbox/DS.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index d8824a55..e085a010 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -69,7 +69,11 @@ Reset all state sub Reset { do { $in_loop = undef; # first in case DESTROY callbacks use this - %DescriptorMap = (); + # clobbering $Poller may call DSKQXS::DESTROY, + # we must always have this set to something to avoid + # needing branches before ep_del/ep_mod calls (via ->close). + $Poller = PublicInbox::Select->new; + %DescriptorMap = (); # likely to call ep_del @Timers = (); %UniqTimer = (); @post_loop_do = (); @@ -77,8 +81,8 @@ sub Reset { # we may be iterating inside one of these on our stack my @q = delete @Stack{keys %Stack}; for my $q (@q) { @$q = () } - $AWAIT_PIDS = $nextq = $ToClose = undef; - $Poller = undef; # may call DSKQXS::DESTROY + $AWAIT_PIDS = $nextq = $ToClose = undef; # may call ep_del + $Poller = PublicInbox::Select->new; } while (@Timers || keys(%Stack) || $nextq || $AWAIT_PIDS || $ToClose || keys(%DescriptorMap) || @post_loop_do || keys(%UniqTimer));