xap_helper: implement alarm(2)-based timeout
commitd4529bfbce012361c802a21ce2147ae3967c11eb
authorEric Wong <e@80x24.org>
Fri, 26 Apr 2024 11:29:44 +0000 (26 11:29 +0000)
committerEric Wong <e@80x24.org>
Sun, 28 Apr 2024 17:05:33 +0000 (28 17:05 +0000)
tree434254c3eb9db0e0624253fb59f1339ebb429f89
parentc807cdd1c2e85237e769532a36819888ca97f8b1
xap_helper: implement alarm(2)-based timeout

alarm(2) delivering SIGALRM seems sufficient for Xapian since
Xapian doesn't block signals (which would necessitate the use of
SIGKILL via RLIMIT_CPU hard limit).  When Xapian gets stuck in
`D' state on slow storage, SIGKILL would not make a difference,
either (at least not on Linux).

Relying on RLIMIT_CPU is also trickier since we must account for
CPU time already consumed by a process for unrelated requests.
Thus we just rely on a simple alarm-based timeout.  This also
avoids requiring the optional BSD::Resource module in the (mostly)
Perl implementation (and avoids potential bugs given my meager
arithmetic skills).
lib/PublicInbox/XapHelper.pm
lib/PublicInbox/xap_helper.h
t/xap_helper.t