Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions tests/FrankenPhp/FrankenPhpReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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.
Expand All @@ -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');
Expand Down
5 changes: 4 additions & 1 deletion tests/GoNetHttp/GoReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading