Skip to content
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

Piping from a stream that has already reached EOF #36

Closed
mbonneau opened this issue Feb 3, 2016 · 1 comment · Fixed by #71
Closed

Piping from a stream that has already reached EOF #36

mbonneau opened this issue Feb 3, 2016 · 1 comment · Fixed by #71

Comments

@mbonneau
Copy link

mbonneau commented Feb 3, 2016

I am not sure if this is actually an issue, but if you pipe from a stream that has already reached EOF (or closed some other way) pipe will cause the loop to never exit because no events are sent - or will ever be sent - to the destination stream.

It seems that it would be better for pipe to close the destination stream if isReadable is false.

Reproduce:

<?php

require_once __DIR__ . '/vendor/autoload.php';

system('echo Testing > somefile.txt');

$loop = \React\EventLoop\Factory::create();

$readStream = new \React\Stream\Stream(fopen("somefile.txt", "r"), $loop);

$loop->addTimer(1, function () use ($loop, $readStream) {
    $output = new \React\Stream\Stream(STDOUT, $loop);
    $readStream->pipe($output);
});

$loop->run();
@clue
Copy link
Member

clue commented Feb 13, 2016

It seems that it would be better for pipe to close the destination stream if isReadable is false.

Thanks for spotting 👍 I think the suggested change makes perfect the sense and I would consider the current behavior a bug.

The default behavior of pipe() is to end() the destination stream once the source stream also ends (though this can be controlled by the user). In this case it also makes sense to close the destination stream immediately if the the source stream is already closed at the beginning.

Note that the problem you're observing is also conflated with #37 because your $output stream is actually assumed to be a duplex stream by default. If you call $output->pause(), then the output stream will still not end (arguably incorrect), but the loop should exit (correct).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants