Skip to content

Commit

Permalink
buffer chunk after flushing buffer in write if paused
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Caleb ツ Everett committed Dec 1, 2021
1 parent 7f71279 commit d4204ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ module.exports = class Minipass extends Stream {
// because we're mid-write, so that'd be bad.
if (this[BUFFERLENGTH] !== 0)
this[FLUSH](true)
this.emit('data', chunk)

// if we are still flowing after flushing the buffer we can emit the
// chunk otherwise we have to buffer it.
this.flowing
? this.emit('data', chunk)
: this[BUFFERPUSH](chunk)
} else
this[BUFFERPUSH](chunk)

Expand Down

0 comments on commit d4204ae

Please sign in to comment.