($req->{srch}->has_threadid ? 1 : 0)
}
+sub cmd_test_sleep { select(undef, undef, undef, 0.01) while 1 }
+
sub iter_retry_check ($) {
if (ref($@) =~ /\bDatabaseModifiedError\b/) {
$_[0]->{srch}->reopen;
$new->{qp} = $new->qparse_new;
$new;
};
+ my $timeo = $req->{K};
+ alarm($timeo) if $timeo;
$fn->($req, @argv);
+ alarm(0) if $timeo;
}
sub recv_loop {
}
scalar(@fds) or exit(66); # EX_NOINPUT
die "recvmsg: $!" if !defined($fds[0]);
- PublicInbox::DS::block_signals();
+ PublicInbox::DS::block_signals(POSIX::SIGALRM);
my $req = bless {}, __PACKAGE__;
my $i = 0;
open($req->{$i++}, '+<&=', $_) for @fds;
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
+#include <poll.h>
#include <assert.h>
#include <err.h> // BSD, glibc, and musl all have this
return false;
}
+static bool cmd_test_sleep(struct req *req)
+{
+ for (;;) poll(NULL, 0, 10);
+ return false;
+}
#include "xh_mset.h" // read-only (WWW, IMAP, lei) stuff
#include "xh_cidx.h" // CodeSearchIdx.pm stuff
CMD(dump_ibx), // many inboxes
CMD(dump_roots), // per-cidx shard
CMD(test_inspect), // least common commands last
+ CMD(test_sleep), // least common commands last
};
#define MY_ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
free_srch(kbuf.srch);
goto cmd_err; // srch_init already warned
}
+ if (req->timeout_sec)
+ alarm(req->timeout_sec > UINT_MAX ?
+ UINT_MAX : (unsigned)req->timeout_sec);
try {
if (!req->fn(req))
warnx("`%s' failed", req->argv[0]);
} catch (...) {
warn("unhandled exception");
}
+ if (req->timeout_sec)
+ alarm(0);
cmd_err:
return; // just be silent on errors, for now
}
DELSET(SIGXFSZ);
#undef DELSET
CHECK(int, 0, sigdelset(&workerset, SIGUSR1));
+ CHECK(int, 0, sigdelset(&fullset, SIGALRM));
if (nworker == 0) { // no SIGTERM handling w/o workers
recv_loop();
require PublicInbox::AutoReap;
use PublicInbox::IPC;
require PublicInbox::XapClient;
+use PublicInbox::DS qw(now);
use autodie;
my ($tmp, $for_destroy) = tmpdir();
my @oids = (join('', @res) =~ /^([a-f0-9]{7}) /gms);
is $nr_out, scalar(@oids), "output count matches $xhc->{impl}" or
diag explain(\@res, \@err);
+
+ if ($ENV{TEST_XH_TIMEOUT}) {
+ diag 'testing timeouts...';
+ for my $j (qw(0 1)) {
+ my $t0 = now;
+ $r = $xhc->mkreq(undef, qw(test_sleep -K 1 -d),
+ $ibx_idx[0]);
+ is readline($r), undef, 'got EOF';
+ my $diff = now - $t0;
+ ok $diff < 3, "timeout didn't take too long -j$j";
+ ok $diff >= 0.9, "timeout didn't fire prematurely -j$j";
+ $xhc = PublicInbox::XapClient::start_helper('-j1');
+ }
+ }
}
done_testing;