From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 34AD91FA01 for ; Fri, 15 Oct 2021 13:30:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/3] lei note-event: fix explicit flush reliability Date: Fri, 15 Oct 2021 13:30:56 +0000 Message-Id: <20211015133056.6845-4-e@80x24.org> In-Reply-To: <20211015133056.6845-1-e@80x24.org> References: <20211015133056.6845-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We need to send the socket over to lei/store and wait for the kernel to drop the socket refcount down to zero before script/lei can exit. This is not a new bug and only caused very sporadic test failures. I only noticed it while simplifying IPC stuff. --- lib/PublicInbox/LeiNoteEvent.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/LeiNoteEvent.pm b/lib/PublicInbox/LeiNoteEvent.pm index ba4dfd49..1749c98f 100644 --- a/lib/PublicInbox/LeiNoteEvent.pm +++ b/lib/PublicInbox/LeiNoteEvent.pm @@ -11,10 +11,11 @@ use PublicInbox::DS; our $to_flush; # { cfgpath => $lei } -sub flush_lei ($) { - my ($lei) = @_; - my $lne = delete $lei->{cfg}->{-lei_note_event}; - $lne->wq_close if $lne; # runs _lei_wq_eof; +sub flush_lei ($;$) { + my ($lei, $manual) = @_; + my $lne = delete $lei->{cfg}->{-lei_note_event} // return; + $lne->{lei_sock} = $lei->{sock} if $manual; + $lne->wq_close; # runs _lei_wq_eof; } # we batch up writes and flush every 5s (matching Linux default @@ -67,7 +68,7 @@ sub lei_note_event { die "BUG: unexpected: @rest" if @rest; my $cfg = $lei->_lei_cfg or return; # gone (race) my $sto = $lei->_lei_store or return; # gone - return flush_lei($lei) if $folder eq 'done'; # special case + return flush_lei($lei, 1) if $folder eq 'done'; # special case my $lms = $lei->lms or return; $lms->lms_write_prepare if $new_cur eq ''; # for ->clear_src below $lei->{opt}->{quiet} = 1; @@ -111,8 +112,8 @@ sub ipc_atfork_child { sub _lei_wq_eof { # EOF callback for main lei daemon my ($lei) = @_; - delete $lei->{lne} or return $lei->fail; - $lei->sto_done_request; + my $lne = delete $lei->{lne} or return $lei->fail; + $lei->sto_done_request($lne->{lei_sock}); } 1;