my ($self) = @_;
        my $ppid = $self->{-wq_ppid};
        wq_kill($self) if $ppid && $ppid == $$;
+       my $err = $?;
        wq_close($self);
        wq_wait_old($self);
        ipc_worker_stop($self);
+       $? = $err if $err;
 }
 
 sub detect_nproc () {
 
                        my $wq = delete $self->{$f} or next;
                        $wq->DESTROY;
                }
-               # cleanup anything that has tempfiles
-               delete @$self{qw(ovv dedupe)};
+               # cleanup anything that has tempfiles or open file handles
+               %PATH2CFG = ();
+               delete @$self{qw(ovv dedupe sto cfg)};
                if (my $signum = ($code & 127)) { # usually SIGPIPE (13)
                        $SIG{PIPE} = 'DEFAULT'; # $SIG{$signum} doesn't work
                        kill $signum, $$;
        my ($self) = @_;
        $self->{1}->autoflush(1) if $self->{1};
        stop_pager($self);
+       my $err = $?;
        my $oneshot_pids = delete $self->{"pid.$self.$$"} or return;
        waitpid($_, 0) for keys %$oneshot_pids;
+       $? = $err if $err; # preserve ->fail or ->x_it code
 }
 
 1;
 
        my $end = $lk->lock_for_scope;
        return @ret if -f $stamp;
 
-       require PublicInbox::InboxWritable;
        local $ENV{PI_CONFIG} = $pi_config;
        for my $V (1, 2) {
                run_script([qw(-init), "-V$V", "t$V",
                                "$test_home/t$V", "http://example.com/t$V",
                                "t$V\@example.com" ]) or BAIL_OUT "init v$V";
        }
+       require PublicInbox::Config;
+       require PublicInbox::InboxWritable;
        my $cfg = PublicInbox::Config->new;
        my $seen = 0;
        $cfg->each_inbox(sub {
 
        like($lei_out, qr!\Q$t2\E!, 't2 added to ls-externals');
 
        ok(!$lei->('add-external', $t2, '--mirror', "$http/t2/"),
-               '--mirror fails if reused');
+               '--mirror fails if reused') or diag "$lei_err.$lei_out = $?";
 
        ok($lei->('ls-external'), 'ls-external');
        like($lei_out, qr!\Q$t2\E!, 'still in ls-externals');