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 227331F461 for ; Sat, 29 Jun 2019 07:18:54 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] t/ds-leak: fix race Date: Sat, 29 Jun 2019 07:18:53 +0000 Message-Id: <20190629071853.21833-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We need to ensure we run lsof on the sleep(1) process, and not the fork of ourselves before execve(2). This race applies when we're using the default pure-Perl spawn() implementation. --- t/ds-leak.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/ds-leak.t b/t/ds-leak.t index dd8446dc..34ffc125 100644 --- a/t/ds-leak.t +++ b/t/ds-leak.t @@ -15,9 +15,21 @@ if ('close-on-exec for epoll and kqueue') { PublicInbox::DS->SetLoopTimeout(0); PublicInbox::DS->SetPostLoopCallback(sub { 0 }); + + # make sure execve closes if we're using fork() + my ($r, $w); + pipe($r, $w) or die "pipe: $!"; + PublicInbox::DS->AddTimer(0, sub { $pid = spawn([qw(sleep 10)]) }); PublicInbox::DS->EventLoop; ok($pid, 'subprocess spawned'); + + # wait for execve, we need to ensure lsof sees sleep(1) + # and not the fork of this process: + close $w or die "close: $!"; + my $l = <$r>; + is($l, undef, 'cloexec works and sleep(1) is running'); + my @of = grep(/$evfd_re/, `lsof -p $pid 2>/dev/null`); my $err = $?; SKIP: { -- EW