Skip to content

Only emit permanent errors and otherwise keep retrying #52

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

Merged
merged 4 commits into from
Aug 22, 2016

Conversation

clue
Copy link
Member

@clue clue commented Aug 19, 2016

Only report errors if nothing could be sent.

Any hard (permanent) error will fail to send any data at all.
Sending excessive amounts of data will only flush some data and then
report a temporary error (EAGAIN) which we do not raise here in order
to keep the stream open for further tries to write.

Should this turn out to be a permanent error later, it will eventually
send nothing and we can detect this.

This fixes a (very sublte) regression introduced via #25.
This also adds a bunch of unit tests so we hopefully no longer rely on any external test cases. The Buffer now has 100% code coverage in our tests.

I've intentionally kept this changeset to a minimum in order to ease review. I'll file a second PR to streamline the error handling system after this PR is in.

Also note that this changeset has an implicit dependency on #51, empty writes would otherwise raise an error event (see that PR for more details).

@clue clue added the bug label Aug 19, 2016
@clue clue added this to the v0.4.4 milestone Aug 19, 2016
@@ -102,7 +109,7 @@ public function handleWrite()
return;
}

if ($sent === false) {
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on removing this block of code all together?

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 currently required, see the testWriteEmitsErrorWhenResourceIsNotWritable() test case below.

Yes, this code does contain some duplication.
I've intentionally kept this changeset to a minimum in order to ease review. I'll file a second PR to streamline the error handling system after this PR is in.

@@ -58,6 +58,23 @@ public function testWriteReturnsFalseWhenBufferIsFull()
* @covers React\Stream\Buffer::write
* @covers React\Stream\Buffer::handleWrite
*/
public function testWriteEmitsErrorWhenResourceIsNotWritable()
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 test currently fails for HHVM: https://3v4l.org/Z1Ft4

Looks like HHVM does allow writing to read-only streams, while Zend does not...

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this only applies to streams of type MEMORY, i.e. regular file handles work correctly: https://3v4l.org/J467M

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 test will now be skipped on HHVM with a link to this discussion.

This is purely for this very synthetic test case, streams of type MEMORY are not supported by the event loop anyway, so there's no way this could affect a real world program.

Also, streams of type MEMORY are transient (non-permanent) anyway, so there's really little sense in keeping a read-only reference to something that nobody can write to anyway :-)

@clue clue changed the title Only emit permanant errors and otherwise keep retrying Only emit permanent errors and otherwise keep retrying Aug 19, 2016
@cboden cboden merged commit 6d6a843 into reactphp:master Aug 22, 2016
@clue clue deleted the write-feof branch August 22, 2016 09:25
@clue clue mentioned this pull request Sep 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy