Skip to content
Permalink
Browse files

stream: do not emit drain if stream ended

PR-URL: #29086
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information...
ronag authored and BridgeAR committed Aug 11, 2019
1 parent 293c9f0 commit b36a6e9ed5e05f0413bbdfae0d6b4ae6a71f9bb5
Showing with 22 additions and 4 deletions.
  1. +6 −4 lib/_stream_writable.js
  2. +16 −0 test/parallel/test-stream-write-drain.js
@@ -480,15 +480,17 @@ function onwrite(stream, er) {
}

if (sync) {
process.nextTick(afterWrite, stream, state, finished, cb);
process.nextTick(afterWrite, stream, state, cb);
} else {
afterWrite(stream, state, finished, cb);
afterWrite(stream, state, cb);
}
}
}

function afterWrite(stream, state, finished, cb) {
if (!finished && state.length === 0 && state.needDrain) {
function afterWrite(stream, state, cb) {
const needDrain = !state.ending && !stream.destroyed && state.length === 0 &&
state.needDrain;
if (needDrain) {
state.needDrain = false;
stream.emit('drain');
}
@@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const { Writable } = require('stream');

// Don't emit 'drain' if ended

const w = new Writable({
write(data, enc, cb) {
process.nextTick(cb);
},
highWaterMark: 1
});

w.on('drain', common.mustNotCall());
w.write('asd');
w.end();

0 comments on commit b36a6e9

Please sign in to comment.
You can’t perform that action at this time.