Skip to content
Closed
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
25 changes: 23 additions & 2 deletions src/EventLoop/StreamSelectLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,17 @@ private function waitForStreamActivity($timeout)
$read = $this->readStreams;
$write = $this->writeStreams;

$this->streamSelect($read, $write, $timeout);
$n = $this->streamSelect($read, $write, $timeout);
if (false === $n) {
// if a system call has been interrupted, forget about it, let's try again and avoid warning messages.
if ($this->hasSystemCallBeenInterrupted()) {
return;
}

$this->stop();

return;
}

foreach ($read as $stream) {
$key = (int) $stream;
Expand Down Expand Up @@ -252,11 +262,22 @@ protected function streamSelect(array &$read, array &$write, $timeout)
if ($read || $write) {
$except = null;

return stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
return @stream_select($read, $write, $except, $timeout === null ? null : 0, $timeout);
}

usleep($timeout);

return 0;
}

/**
* @return bool
*/
private function hasSystemCallBeenInterrupted()
{
$lastError = error_get_last();

// stream_select returns false when the `select` system call is interrupted by an incoming signal
return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some tests would be much appreciated 👍

Also IIRC, the error messages take the user's LOCALE into account and might be translated to another language. If so, how should we match those?

}
}