-
Notifications
You must be signed in to change notification settings - Fork 168
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
Conversation
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.
In particular, data that was read should not be thrown away, but instead should be written. See whatwg/streams#644. Follows whatwg/streams#726.
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; |
There was a problem hiding this comment.
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?
lgtm |
lgtm e22b3d8 |
In particular, data that was read should not be thrown away, but instead should be written. See whatwg/streams#644. Follows whatwg/streams#726.
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