-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make run-tests.php check for tcp fwrite edge cases #9242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
55325fe
to
8cc8300
Compare
When the recipient is busy or the payload is large, fwrite can block or return a value smaller than the length of the stream. workers in run-tests.php communicates over tcp sockets with the manager. https://cirrus-ci.com/task/5315675320221696?logs=tests#L130 showed notices for fwrite/unserialize This is a similar approach to the approach used in https://github.com/phan/phan/blob/v5/src/Phan/LanguageServer/ProtocolStreamWriter.php for the tcp language server writing.
8cc8300
to
b015f82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good otherwise
/* Wait for up to 10 seconds for the stream to be ready to write again. */ | ||
$result = stream_select($read_streams, $write_streams, $except_streams, 10); | ||
if (!$result) { | ||
echo "ERROR: send_message() stream_select() failed\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "ERROR: send_message() stream_select() failed\n"; | |
fwrite(STDERR, "ERROR: send_message() stream_select() failed\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function error(string $message): void
{
echo "ERROR: {$message}\n";
exit(1);
}
Nothing else in run-tests.php is printing to STDERR or referencing STDERR yet - starting to do that would introduce an inconsistency with similar error logging.
For anything redirecting to a log file, the existing behavior of printing to stdout seems fine, especially since there's no machine-readable output format for run-tests.php as an option
} | ||
$n = @fwrite($stream, substr($data, $bytes_written)); | ||
if ($n === false) { | ||
echo "ERROR: send_message() Failed to write chunk after stream_select: " . error_get_last()['message'] . "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "ERROR: send_message() Failed to write chunk after stream_select: " . error_get_last()['message'] . "\n"; | |
fwrite(STDERR, "ERROR: send_message() Failed to write chunk after stream_select: " . error_get_last()['message'] . "\n"); |
When the recipient is busy or the payload is large, fwrite can block
or return a value smaller than the length of the stream.
workers in run-tests.php communicates over tcp sockets with the manager.
https://cirrus-ci.com/task/5315675320221696?logs=tests#L130
showed notices for fwrite/unserialize
This is a similar approach to that used in
https://github.com/phan/phan/blob/v5/src/Phan/LanguageServer/ProtocolStreamWriter.php
for the tcp language server writing.
Reopening #8023