Skip to content

Fix pipeTo() to ensure all read chunks are written #726

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
Apr 6, 2017

Conversation

domenic
Copy link
Member

@domenic domenic commented Apr 6, 2017

Previously, the spec wording allowed for immediate shutdown if the readable stream became closed, even if there were outstanding writes which did not yet get written. This fixes that, by requiring any already-read chunks to be written when possible.

The reference implementation mostly did not suffer from this, but did in the case where a read completes while a write is ongoing. This was fixed by making its "wait for writes to finish" functionality more robust.

Fixes #644.

Tests: web-platform-tests/wpt#5270

Previously, the spec wording allowed for immediate shutdown if the readable stream became closed, even if there were outstanding writes which did not yet get written. This fixes that, by requiring any already-read chunks to be written when possible.

The reference implementation mostly did not suffer from this, but did in the case where a read completes while a write is ongoing. This was fixed by making its "wait for writes to finish" functionality more robust.

Fixes #644.
@domenic domenic added the piping label Apr 6, 2017
@domenic domenic requested a review from ricea April 6, 2017 09:03
domenic added a commit to web-platform-tests/wpt that referenced this pull request Apr 6, 2017
In particular, data that was read should not be thrown away, but instead should be written. See whatwg/streams#644. Follows whatwg/streams#726.
@domenic
Copy link
Member Author

domenic commented Apr 6, 2017

Note: the two steps (write any read chunks; wait for writes to finish) don't apply in all shutdown cases. In particular they only apply when the source errors or closes. This leads to some duplication. However the alternate approach of only putting those steps underneath their corresponding conditions ("Errors must be propagated forward" and "Closing must be propagated forward") meant you also needed to duplicate the shuttingDown set/check under those conditions. So this version seemed cleanest to me.

if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) {
// Another write may have started while we were waiting on this currentWrite, so we have to be sure to wait
// for that too.
const before = currentWrite;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find the name before a little unclear. I don't have strong feelings about it, but maybe oldCurrentWrite would be better?

@ricea
Copy link
Collaborator

ricea commented Apr 6, 2017

lgtm

@ricea
Copy link
Collaborator

ricea commented Apr 6, 2017

lgtm e22b3d8

domenic added a commit to web-platform-tests/wpt that referenced this pull request Apr 6, 2017
In particular, data that was read should not be thrown away, but instead should be written. See whatwg/streams#644. Follows whatwg/streams#726.
@domenic domenic merged commit 8597d3c into master Apr 6, 2017
@domenic domenic deleted the dont-close-too-early branch April 6, 2017 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

pipeTo() algorithm shuts down too early on readable close()?
2 participants