Description
The Stream
class assumes all stream resources are duplex (r/w) streams, while some may only be readable (e.g. STDIN
) or only be writable (e.g. STDOUT
).
I'm not considering this to be a bug because this happens to be documented behavior, albeit probably unexpected for many newcomers.
The following gist highlights this problem:
$loop = \React\EventLoop\Factory::create();
// by default, this will open a duplex stream (r/w)
$out = new \React\Stream\Stream(STDOUT, $loop);
// this line is completely optional - only here to make this problem more obvious
// the same issue happens without writing any data
$out->write("hello\n");
$loop->run();
The average user would probably assume this to write out some data (if at all) and then exit.
However, this example does not terminate ever. The Stream
class assumes the STDOUT
stream is a duplex stream resource and thus keeps waiting for incoming data infinitely.
In the above example, this problem can be worked around by pausing the stream anywhere like this:
$out->pause();
I'm going to argue that this is counter-intuitive and confusing (what exactly is being paused here?).
Note that a similar problem happens with stream resources that are read-only (e.g. STDIN
) though it's less apparent.
This ticket aims to serve as a reminder for this hardly documented behavior, for the reference and in order to discuss possible alternatives.