unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] ds: Reset: replace Poller object early
Date: Wed,  4 Oct 2023 08:50:56 +0000	[thread overview]
Message-ID: <20231004085059.2115839-2-e@80x24.org> (raw)
In-Reply-To: <20231004085059.2115839-1-e@80x24.org>

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));

  reply	other threads:[~2023-10-04  8:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-04  8:50 [PATCH 0/3] ds fix and cleanups Eric Wong
2023-10-04  8:50 ` Eric Wong [this message]
2023-10-04  8:50 ` [PATCH 2/3] ds: cleanup fork + Reset support Eric Wong
2023-10-04  8:50 ` [PATCH 3/3] ds: make %AWAIT_PIDS a hash, not hashref Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231004085059.2115839-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).