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

write can emit out of order chunks on a partial flush #27

Closed
everett1992 opened this issue Dec 1, 2021 · 0 comments
Closed

write can emit out of order chunks on a partial flush #27

everett1992 opened this issue Dec 1, 2021 · 0 comments

Comments

@everett1992
Copy link

everett1992 commented Dec 1, 2021

minipass/index.js

Lines 166 to 168 in 9bfcf55

if (this[BUFFERLENGTH] !== 0)
this[FLUSH](true)
this.emit('data', chunk)

do {} while (this[FLUSHCHUNK](this[BUFFERSHIFT]()))

If there is more than one chunk in in the buffer list then flush may not write all chunks before a consumer returns false and the stream emits the new chunk the chunks remaining in buffer.

This bug is demonstrated here and causes npm/cli#3884

@everett1992 everett1992 changed the title write can emit errors on a partial flush write can emit out of order chunks on a partial flush Dec 1, 2021
everett1992 pushed a commit to everett1992/minipass that referenced this issue Dec 1, 2021
everett1992 pushed a commit to everett1992/minipass that referenced this issue Dec 1, 2021
everett1992 pushed a commit to everett1992/minipass that referenced this issue Dec 1, 2021
4c5a106 handled a convoluted case where there is a chunk in the buffer
AND  we're in a flowing state during a write call which caused out of
order writes.

The fix was to flush the buffer before emitting the new chunk, but it
didn't account for destinations pausing the stream after flushing part
of the buffer. This caused issues in npm/pacote/npm-registry-fetch.

That specific issue is demonstrated in everett1992/make-fetch-happen-tar-extract-error
and occurs when make-fetch-happen res.body is piped to a tar.extract
stream.

Fixes isaacs#27 npm/cli#3884 make-fetch-happen#63
@isaacs isaacs closed this as completed in 2a0f468 Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant