Skip to content

Commit a4becf7

Browse files
Silently ignore result send failure during shutdown
1 parent 296b521 commit a4becf7

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/Context/Internal/functions.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Amp\Future;
88
use Amp\Parallel\Ipc;
99
use Amp\Serialization\SerializationException;
10+
use Amp\Sync\ChannelException;
1011
use Revolt\EventLoop;
1112

1213
/** @internal */
@@ -23,7 +24,8 @@ function runContext(string $uri, string $key, Cancellation $connectCancellation,
2324
$socket = Ipc\connect($uri, $key, $connectCancellation);
2425
$resultChannel = new StreamChannel($socket, $socket);
2526
} catch (\Throwable $exception) {
26-
\trigger_error($exception->getMessage(), E_USER_ERROR);
27+
\file_put_contents('php://stderr', $exception->getMessage(), \FILE_APPEND);
28+
exit(255);
2729
}
2830

2931
try {
@@ -72,11 +74,12 @@ function runContext(string $uri, string $key, Cancellation $connectCancellation,
7274
// Serializing the result failed. Send the reason why.
7375
$resultChannel->send(new ExitFailure($exception));
7476
}
77+
} catch (ChannelException) {
78+
// The parent may have already closed the channel after reading
79+
// the result (e.g. during shutdown). Nothing left to do.
7580
} catch (\Throwable $exception) {
76-
\trigger_error(\sprintf(
77-
"Could not send result to parent: '%s'; be sure to shutdown the child before ending the parent",
78-
$exception->getMessage(),
79-
), E_USER_ERROR);
81+
file_put_contents('php://stderr', $exception->getMessage(), \FILE_APPEND);
82+
exit(255);
8083
}
8184
});
8285

src/Context/Internal/process-runner.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
}
3636

3737
if (!isset($autoloadPath)) {
38-
\trigger_error(
39-
"Could not locate autoload.php in any of the following files: " . \implode(", ", $paths),
40-
E_USER_ERROR,
41-
);
38+
\file_put_contents('php://stderr', "Could not locate autoload.php in any of the following files: " . \implode(", ", $paths), \FILE_APPEND);
39+
exit(255);
4240
}
4341

4442
/** @psalm-suppress UnresolvableInclude */
@@ -58,15 +56,18 @@
5856
/** @var list<string> $argv */
5957

6058
if (!isset($argv[1])) {
61-
\trigger_error("No socket path provided", E_USER_ERROR);
59+
\file_put_contents('php://stderr', "No socket path provided", \FILE_APPEND);
60+
exit(255);
6261
}
6362

6463
if (!isset($argv[2]) || !\is_numeric($argv[2])) {
65-
\trigger_error("No key length provided", E_USER_ERROR);
64+
\file_put_contents('php://stderr', "No key length provided", \FILE_APPEND);
65+
exit(255);
6666
}
6767

6868
if (!isset($argv[3]) || !\is_numeric($argv[3])) {
69-
\trigger_error("No timeout provided", E_USER_ERROR);
69+
\file_put_contents('php://stderr', "No timeout provided", \FILE_APPEND);
70+
exit(255);
7071
}
7172

7273
[, $uri, $length, $timeout] = $argv;
@@ -82,7 +83,8 @@
8283
$cancellation = new TimeoutCancellation($timeout);
8384
$key = Ipc\readKey(ByteStream\getStdin(), $cancellation, $length);
8485
} catch (\Throwable $exception) {
85-
\trigger_error($exception->getMessage(), E_USER_ERROR);
86+
\file_put_contents('php://stderr', $exception->getMessage(), \FILE_APPEND);
87+
exit(255);
8688
}
8789

8890
runContext($uri, $key, $cancellation, $argv);

0 commit comments

Comments
 (0)