Skip to content

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

Merged
merged 1 commit into from
Oct 8, 2022

Conversation

TysonAndre
Copy link
Contributor

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

@TysonAndre TysonAndre requested a review from iluuu1994 August 3, 2022 12:22
@TysonAndre TysonAndre force-pushed the run-tests-fwrite-error branch from 55325fe to 8cc8300 Compare August 5, 2022 19:53
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.
@TysonAndre TysonAndre force-pushed the run-tests-fwrite-error branch from 8cc8300 to b015f82 Compare August 7, 2022 17:08
@krakjoe krakjoe requested a review from bukka August 10, 2022 13:05
Copy link
Member

@iluuu1994 iluuu1994 left a 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "ERROR: send_message() stream_select() failed\n";
fwrite(STDERR, "ERROR: send_message() stream_select() failed\n");

Copy link
Contributor Author

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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");

@TysonAndre TysonAndre merged commit d498908 into php:master Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants