From 5c1466fa434538c5938594bac400c49ae131a54d Mon Sep 17 00:00:00 2001 From: CPANSec Security Scanner Bot Date: Tue, 24 Nov 2026 14:33:17 +0000 Subject: [PATCH] Net::Server::Thread: ignore SIGALRM in the main thread Net::Server::HTTP and Net::Server::PSGI time each request with alarm() and a local ALRM handler, and the default process_request does the same. Under the Thread server type that code runs in a handler thread, but alarm() is process-wide and perl handles SIGALRM in the main thread, which had no ALRM handler. When a request timed out, for example a client that connected and sent nothing until timeout_header expired, SIGALRM killed the whole server process. Register ALRM as ignored in the main thread before the accept loop, unless a handler for it is already in place (sig_passthrough or one set by the application). A request timeout no longer stops the server. This does not make the timeouts work per thread. A handler thread's ALRM handler never runs, threads->kill does not interrupt a thread that is blocked in a read, and with several threads each alarm() call replaces the previous one. A client that stalls now keeps its thread until it disconnects instead of stopping the server. The POD says so and points to PreFork or Fork where per-request timeouts are needed. Notes for deciding whether to apply this patch: - This stops a request timeout from killing the server. It does not make request timeouts work under the Thread server type: a client that stalls keeps its thread until it disconnects. - Without the max_servers fix for Net::Server::Thread, nothing bounds the number of threads stalled clients can hold. - Where per-request timeouts are needed, use the PreFork or Fork server type. - Not tested on a running server. It was checked by review and by applying it to Net-Server 2.018. - Applies on its own to Net-Server 2.018, and together with the other CPANSec patches for Net-Server 2.018 when they are applied in CVE-ID order. --- lib/Net/Server/Thread.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Net/Server/Thread.pm b/lib/Net/Server/Thread.pm index 89e940c..64ab89c 100644 --- a/lib/Net/Server/Thread.pm +++ b/lib/Net/Server/Thread.pm @@ -48,6 +48,13 @@ sub loop { HUP => sub { $self->sig_hup() }, ); + # alarm() is process-wide and SIGALRM is delivered to the main thread, + # so an ALRM handler set in a handler thread never runs. Without this + # a request timeout (timeout_header, timeout_idle) would kill the server. + # A handler already set up for ALRM (e.g. sig_passthrough) is kept. + register_sig(ALRM => 'IGNORE') + if ! Net::Server::SIG::sig_is_registered('ALRM') && ref($SIG{'ALRM'}) ne 'CODE'; + while (1) { threads->yield(); @@ -173,6 +180,14 @@ request may be lengthy or involved. If short and light request are used, perl may not voluntarily give back the used memory. This is highly system dependent. +Request timeouts that use alarm(), such as timeout_header and +timeout_idle in L and L, do not +apply under this personality. The alarm is process-wide and the +SIGALRM is handled by the main thread, which ignores it so that one +slow client does not stop the server. A client that stalls keeps its +thread until it disconnects. Use L or +L where per-request timeouts are needed. + =head1 ARGUMENTS =over 4 -- 2.53.0