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-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 9CB051FA00 for ; Thu, 4 Mar 2021 09:03:16 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/6] lei_xsearch: cleanup {pkt_op_p} on exceptions Date: Thu, 4 Mar 2021 17:03:13 +0800 Message-Id: <20210304090316.9568-4-e@80x24.org> In-Reply-To: <20210304090316.9568-1-e@80x24.org> References: <20210304090316.9568-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We must ensure pkt_op_p doesn't live beyond the scope of ->do_query in the top-level lei-daemon, otherwise it can leave a stray socket hanging around in case of exceptions. --- lib/PublicInbox/LeiXSearch.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index 45815180..059aa284 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -416,6 +416,11 @@ sub ipc_atfork_child { $self->SUPER::ipc_atfork_child; } +sub delete_pkt_op { # OnDestroy callback + my $unclosed_after_die = delete($_[0])->{pkt_op_p} or return; + close $unclosed_after_die; +} + sub do_query { my ($self, $lei) = @_; my $l2m = $lei->{l2m}; @@ -431,6 +436,7 @@ sub do_query { 'incr_start_query' => [ \&incr_start_query, $self, $l2m ], }; $lei->{auth}->op_merge($ops, $l2m) if $l2m && $lei->{auth}; + my $od = PublicInbox::OnDestroy->new($$, \&delete_pkt_op, $lei); ($lei->{pkt_op_c}, $lei->{pkt_op_p}) = PublicInbox::PktOp->pair($ops); $lei->{1}->autoflush(1); $lei->start_pager if delete $lei->{need_pager};