]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watch: avoid potential race condition while quitting
authorEric Wong <e@80x24.org>
Mon, 26 Jun 2017 17:44:41 +0000 (17:44 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Jun 2017 17:44:41 +0000 (17:44 +0000)
We must not trigger future activity when initializing
a -watch shutdown.

lib/PublicInbox/WatchMaildir.pm

index 8e10e43f056c677d4deb6e116a71692a55eed704..5ae3d21f31d7f9f1c6988e976f9bde0d0c4005ff 100644 (file)
@@ -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;
        }