Skip to content

Commit 5856823

Browse files
committed
streams2: Fix duplex no-half-open logic
1 parent 286aa04 commit 5856823

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

lib/_stream_duplex.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,17 @@ function Duplex(options) {
4747
if (options && options.allowHalfOpen === false)
4848
this.allowHalfOpen = false;
4949

50-
this.once('finish', onfinish);
5150
this.once('end', onend);
5251
}
5352

54-
// the no-half-open enforcers.
55-
function onfinish() {
56-
// if we allow half-open state, or if the readable side ended,
57-
// then we're ok.
58-
if (this.allowHalfOpen || this._readableState.ended)
59-
return;
60-
61-
// mark that we're done.
62-
this._readableState.ended = true;
63-
64-
// tell the user
65-
if (this._readableState.length === 0)
66-
this.emit('end');
67-
else
68-
this.emit('readable');
69-
}
70-
53+
// the no-half-open enforcer
7154
function onend() {
7255
// if we allow half-open state, or if the writable side ended,
7356
// then we're ok.
7457
if (this.allowHalfOpen || this._writableState.ended)
7558
return;
7659

77-
// just in case the user is about to call write() again.
78-
this.write = function() {
79-
return false;
80-
};
81-
8260
// no more data can be written.
83-
this.end();
61+
// But allow more writes to happen in this tick.
62+
process.nextTick(this.end.bind(this));
8463
}

0 commit comments

Comments
 (0)