* [PATCH] ds: use a dummy poller during Reset
@ 2023-10-10 10:09 7% Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2023-10-10 10:09 UTC (permalink / raw)
To: meta
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 | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 26cc83f0..eefbdcc3 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -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)
^ permalink raw reply related [relevance 7%]
* [PATCH 1/3] ds: Reset: replace Poller object early
2023-10-04 8:50 7% [PATCH 0/3] ds fix and cleanups Eric Wong
@ 2023-10-04 8:50 7% ` Eric Wong
0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2023-10-04 8:50 UTC (permalink / raw)
To: meta
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));
^ permalink raw reply related [relevance 7%]
* [PATCH 0/3] ds fix and cleanups
@ 2023-10-04 8:50 7% Eric Wong
2023-10-04 8:50 7% ` [PATCH 1/3] ds: Reset: replace Poller object early Eric Wong
0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2023-10-04 8:50 UTC (permalink / raw)
To: meta
1/3 fixes a bug I noticed in syslog during a deploy.
The rest hopefully make things more robust and less
error-prone from typos.
Eric Wong (3):
ds: Reset: replace Poller object early
ds: cleanup fork + Reset support
ds: make %AWAIT_PIDS a hash, not hashref
lib/PublicInbox/DS.pm | 39 +++++++++++++++++++++------------------
lib/PublicInbox/LEI.pm | 2 +-
2 files changed, 22 insertions(+), 19 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-3 of 3 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-10-04 8:50 7% [PATCH 0/3] ds fix and cleanups Eric Wong
2023-10-04 8:50 7% ` [PATCH 1/3] ds: Reset: replace Poller object early Eric Wong
2023-10-10 10:09 7% [PATCH] ds: use a dummy poller during Reset Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).