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

Only close stream when the we reached end of the stream #139

Merged
merged 1 commit into from
Dec 31, 2018

Conversation

WyriHaximus
Copy link
Member

@WyriHaximus WyriHaximus commented Nov 24, 2018

While working on reactphp/event-loop#112 I ran into an issue with suddenly closed streams. Traced the issue down to '' coming from streams when using the ext-uv loop. Adding this check before closing the stream resolved the issue for ext-uv.

Todo:

  • Close stream only when reached EOF
  • Tests

Relates to reactphp/event-loop#112

@WyriHaximus
Copy link
Member Author

Please note that this PR doesn't contain actual code change at the moment. I'll create tests first and commit them before committing the fix to show tests work appropriately.

@WyriHaximus WyriHaximus changed the title [WIP] Only close stream when the we reached end of the stream Only close stream when the we reached end of the stream Nov 25, 2018
@WyriHaximus WyriHaximus requested review from clue and jsor November 25, 2018 20:15
{
$loop = $this->createLoopMock();

$conn = new ReadableResourceStream(STDIN, $loop);
Copy link
Member

Choose a reason for hiding this comment

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

The test for DuplexResourceStream LGTM, can you change this one to also avoid using any external resources?

STDIN is stateful and this will change it to non-blocking mode which will persist even after the test suite has terminated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into that 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

And I recall again why I used STDIN, it was the quickest working stream available xD

WyriHaximus added a commit to WyriHaximus-secret-labs/stream that referenced this pull request Dec 31, 2018
@WyriHaximus WyriHaximus added this to the v1.1.0 milestone Dec 31, 2018
@WyriHaximus
Copy link
Member Author

Ping @jsor @clue let me know if this is 👍 or 👎 . I'll squash and merge on a 👍 .

{
list($stream, $_) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
Copy link

Choose a reason for hiding this comment

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

This will fail on Windows.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is used throughout the rest suite. If this breaks on windows a follow up PR for all of them seems more appropriate to be honest

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

Squash and we're ready to go :shipit:

@WyriHaximus
Copy link
Member Author

Squashed everything into one commit, for those interested the original history can be found at: https://github.com/WyriHaximus-secret-labs/stream/tree/ext-uf-feof-history

@WyriHaximus WyriHaximus merged commit 5040a37 into reactphp:master Dec 31, 2018
clue added a commit to clue-labs/socket that referenced this pull request Jan 2, 2019
Construct underlying stream to always consume complete receive buffer.
This avoids stale data in TLS buffers and also works around possible
buffering issues in legacy PHP versions. The buffer size is limited
due to TCP/IP buffers anyway, so this should not affect usage otherwise.

This builds on top of reactphp/stream#139 to
work around a bug in PHP where reading from a TLS 1.3 stream resource
would hang with 100% CPU usage due to the changed TLS 1.3 handshake.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants