]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: use a dummy poller during Reset
authorEric Wong <e@80x24.org>
Tue, 10 Oct 2023 10:09:04 +0000 (10:09 +0000)
committerEric Wong <e@80x24.org>
Tue, 10 Oct 2023 19:11:46 +0000 (19:11 +0000)
commit 1897c3be1ed644a05f96ed06cde4a9cc2ad0e5a4
(ds: Reset: replace Poller object early, 2023-10-04)
was not effective at eliminating the following message
at daemon shutdown:

Can't call method "FILENO" on an undefined value at
.../PublicInbox/Select.pm line 34 during global destruction.

This seems down to some tied objects having unpredictable
destruction order.  So use a dummy class to ensure its ep_*
methods never call the tied `FILENO' method at all since
dropping the Poller object will release any resources it holds.

lib/PublicInbox/DS.pm

index 26cc83f0853a50323ac48cb277486199b6a319c5..eefbdcc3ec0716cfb341e2d11854ec4fc40003d1 100644 (file)
@@ -67,12 +67,12 @@ Reset all state
 
 =cut
 sub Reset {
+       $Poller = bless [], 'PublicInbox::DummyPoller';
        do {
                $in_loop = undef; # first in case DESTROY callbacks use this
                # 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 = ();
@@ -82,7 +82,6 @@ sub Reset {
                @$cur_runq = () if $cur_runq;
                $nextq = $ToClose = undef; # may call ep_del
                %AWAIT_PIDS = ();
-               $Poller = PublicInbox::Select->new;
        } while (@Timers || $nextq || keys(%AWAIT_PIDS) ||
                $ToClose || keys(%DescriptorMap) ||
                @post_loop_do || keys(%UniqTimer) ||
@@ -738,6 +737,14 @@ sub awaitpid {
        }
 }
 
+package PublicInbox::DummyPoller; # only used during Reset
+use v5.12;
+
+sub ep_del {}
+no warnings 'once';
+*ep_add = \&ep_del;
+*ep_mod = \&ep_del;
+
 1;
 
 =head1 AUTHORS (Danga::Socket)