From f10a69b1291622eb3f827cc81b60c404856af089 Mon Sep 17 00:00:00 2001 From: stefansorge <3419073+sorge-it@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:58:25 +0100 Subject: [PATCH] test: end the references without waiting for their requests On SIGTERM, FrankenPHP waits without end for a script that still reads the body of an open connection, and proc_close() with it. The macOS job of PR 2 hung in GoNetHttp with FrankenPHP processes left, which fits. The references now end with SIGKILL; lingers() reads at most 5 seconds. --- tests/FrankenPhp/FrankenPhpReference.php | 18 ++++++++++++++---- tests/GoNetHttp/GoReference.php | 5 ++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/FrankenPhp/FrankenPhpReference.php b/tests/FrankenPhp/FrankenPhpReference.php index 96fe22c..37fafcc 100644 --- a/tests/FrankenPhp/FrankenPhpReference.php +++ b/tests/FrankenPhp/FrankenPhpReference.php @@ -202,8 +202,7 @@ public function goVersion(): string public function stop(): void { foreach ($this->servers as [$process]) { - proc_terminate($process); - proc_close($process); + $this->kill($process); } $this->servers = []; @@ -232,6 +231,18 @@ private static function run(array $command): array return [$status, $output.stream_get_contents($errors)]; } + /** + * Ends the server with SIGKILL. On SIGTERM, FrankenPHP waits without end for a script that + * still reads the body of a client that keeps its connection open, and `proc_close()` with it. + * + * @param resource $process + */ + private function kill(mixed $process): void + { + proc_terminate($process, 9); + proc_close($process); + } + /** * The port of FrankenPHP with the php.ini, the app, and the options of the server and of the * site in the Caddyfile, started on the first call. @@ -250,8 +261,7 @@ private function port(array $ini, string $app, string $server = '', string $site // The fuzz test takes limits at random; a server for each would hold hundreds of threads. if (count($this->servers) >= 8) { [$process] = array_shift($this->servers); - proc_terminate($process); - proc_close($process); + $this->kill($process); } $free = stream_socket_server('tcp://127.0.0.1:0'); diff --git a/tests/GoNetHttp/GoReference.php b/tests/GoNetHttp/GoReference.php index 062e3e9..ce1ef14 100644 --- a/tests/GoNetHttp/GoReference.php +++ b/tests/GoNetHttp/GoReference.php @@ -159,8 +159,11 @@ public function lingers(string $bytes, Limits $limits): bool try { fwrite($client, $bytes); stream_set_timeout($client, 5); + $deadline = hrtime(true) / 1e9 + 5; - while (! feof($client) && fread($client, 1 << 16) !== false) { + // A read that times out gives '', not false: without the deadline, a Go that does not + // close would hold the suite. + while (! feof($client) && fread($client, 1 << 16) !== false && hrtime(true) / 1e9 < $deadline) { } // The first write after a close gets the reset; the second fails on it.