From 9ae2454c474b8984235ef7607efc585f8a50f2bc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 26 Jun 2017 17:44:41 +0000 Subject: watch: avoid potential race condition while quitting We must not trigger future activity when initializing a -watch shutdown. --- lib/PublicInbox/WatchMaildir.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 8e10e43f..5ae3d21f 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -225,7 +225,7 @@ sub watch { sub trigger_scan { my ($self, $base) = @_; - my $dir = $self->{scandir} or die "not watch-ing, yet\n"; + my $dir = $self->{scandir} or return; open my $fh, '>', "$dir/$base" or die "open $dir/$base failed: $!\n"; close $fh or die "close $dir/$base failed: $!\n"; } @@ -235,6 +235,7 @@ sub scan { if ($path =~ /quit\z/) { %{$self->{opendirs}} = (); _done_for_now($self); + delete $self->{scandir}; $self->{quit} = 1; return; } -- cgit v1.2.3-24-ge0c7