diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index c5b62582aebad7..9f53da30b8ad72 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -705,6 +705,9 @@ Readable.prototype.pipe = function(dest, pipeOpts) { debug('false write response, pause', state.awaitDrain); state.awaitDrain++; } + if (!cleanedUp) { + src.pause(); + } if (!ondrain) { // When the dest drains, it reduces the awaitDrain counter // on the source. This would be more elegant with a .once() @@ -713,7 +716,6 @@ Readable.prototype.pipe = function(dest, pipeOpts) { ondrain = pipeOnDrain(src); dest.on('drain', ondrain); } - src.pause(); } } diff --git a/test/parallel/test-stream-readable-unpipe-resume.js b/test/parallel/test-stream-readable-unpipe-resume.js new file mode 100644 index 00000000000000..b40f724bccfc83 --- /dev/null +++ b/test/parallel/test-stream-readable-unpipe-resume.js @@ -0,0 +1,20 @@ +'use strict'; + +const common = require('../common'); +const stream = require('stream'); +const fs = require('fs'); + +const readStream = fs.createReadStream(process.execPath); + +const transformStream = new stream.Transform({ + transform: common.mustCall(() => { + readStream.unpipe(); + readStream.resume(); + }) +}); + +readStream.on('end', common.mustCall()); + +readStream + .pipe(transformStream) + .resume();