-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Closed STDIN returns endless stream of random data #81
Comments
PHP 7.1.2 from Docker PHP 7.0.16 from Docker PHP 7.0.15 on Ubuntu 16.04: PHP 5.6.8 from Docker PHP 5.5.38 from Docker PHP 5.4.45 from Docker PHP 5.3.29 from Docker PHP 5.3.10 on Ubuntu 12.04: |
I executed the gist and got the following:
This looks good to me, nothing about Executed this with this version:
|
Just tried this with Amp, it does indeed dump random data with the <?php
require "vendor/autoload.php";
use Amp\Loop;
// Loop::set(new Loop\NativeDriver);
Loop::run(function () {
Loop::onReadable(STDIN, function ($watcherId) {
var_dump("READ", fread(STDIN, 8192));
var_dump("EOF", feof(STDIN));
if (feof(STDIN)) {
Loop::cancel($watcherId);
}
});
});
|
@kelunik This looks like you're affected by the same issue. Can you report the PHP version and the output of the gist as given above? It looks like this may in fact be a PHP issue, but we have yet to dive deeper. Some systems seem to be not affected (see @legionth's output). In case you're affected, this really affects the most simple scripts, you can really confuse any interactive CLI tool, like psysh, boris, those building on top of Symfony console etc. etc. |
Running on PHP 7.1.3RC1. I don't think this is related to PHP, but probably rather the underlying system. I'm on Ubuntu 16.04.2 LTS. |
Ok, that's not true, it's not done by the system, (1) because Uv and Event wouldn't fail in that case and (2) because |
@clue FD
|
This is due to https://github.com/php/php-src/blob/16ae9f82e82e2aea5d7deaf8f9a9c825a56dfcc1/ext/standard/php_fopen_wrapper.c#L265 just duplicating instead of registering STDIN as an already closed stream. Thanks to @bwoebi for finding the right place. |
Thanks to @kelunik for reporting this upstream: https://bugs.php.net/bug.php?id=74252 It looks like there's little we can do about this on our end, so we may as well document and close this? 👍 |
For the reference only: I'm no longer able to reproduce this issue with a default PHP installation on Ubuntu (PHP 7.0.22-0ubuntu0.17.04.1):
|
I am having the same problem with 7.2-fpm-alpine on docker. |
While working on #37, I've tested the following simple and quite common code to check possible combinations of readable/writable streams and closing/ending either side:
Here's what works as expected:
Here's what does not work (on most of my systems, more below):
It turns out explicitly passing no handle actually results in a default stream for all STDIO streams (STDIN, STDOUT and STERR). Arguably, this may be a sane default behavior if this default stream would follow expected behavior for closed streams, but unfortunately it does not.
Unfortunately, this default stream behaves just like an endless stream of random data. In fact, it actually is
/dev/urandom
. This can be verified by checking/proc/{PID}/fd
. And it turns out this is not in fact related to ReactPHP at all and can be reproduced with the most simple PHP scripts.Here's a very simple gist to reproduce this output:
This SHOULD show
false
(because STDIN is not a valid stream) and SHOULD not include file descriptor0
in the listing.Note that I could reproduce this in multiple setups, but have seen other setups where this does not occur. As such, I'm opening this ticket to gather more information on why this happens and how this could possibly be avoided.
Unless I'm missing something obvious, it looks like this may boil down to an issue in PHP itself, but I'd rather collect more evidence first.
The text was updated successfully, but these errors were encountered: