Skip to content

Commit 4c4be85

Browse files
mscdexMylesBorins
authored andcommitted
Revert "stream: prevent 'end' to be emitted after 'error'"
This reverts commit 0857790. PR-URL: #20449 Fixes: #20334 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent bea4ffc commit 4c4be85

17 files changed

+20
-76
lines changed

lib/_stream_readable.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ function ReadableState(options, stream, isDuplex) {
9999
this.endEmitted = false;
100100
this.reading = false;
101101

102-
// Flipped if an 'error' is emitted.
103-
this.errorEmitted = false;
104-
105102
// a flag to be able to tell if the event 'readable'/'data' is emitted
106103
// immediately, or on a later tick. We set this to true at first, because
107104
// any actions that shouldn't happen until "later" should generally also
@@ -1072,23 +1069,20 @@ function fromList(n, state) {
10721069
function endReadable(stream) {
10731070
var state = stream._readableState;
10741071

1075-
debug('endReadable', state.endEmitted, state.errorEmitted);
1076-
if (!state.endEmitted && !state.errorEmitted) {
1072+
debug('endReadable', state.endEmitted);
1073+
if (!state.endEmitted) {
10771074
state.ended = true;
10781075
process.nextTick(endReadableNT, state, stream);
10791076
}
10801077
}
10811078

10821079
function endReadableNT(state, stream) {
1083-
debug('endReadableNT', state.endEmitted, state.length, state.errorEmitted);
1080+
debug('endReadableNT', state.endEmitted, state.length);
10841081

10851082
// Check that we didn't get one last unshift.
10861083
if (!state.endEmitted && state.length === 0) {
1084+
state.endEmitted = true;
10871085
stream.readable = false;
1088-
1089-
if (!state.errorEmitted) {
1090-
state.endEmitted = true;
1091-
stream.emit('end');
1092-
}
1086+
stream.emit('end');
10931087
}
10941088
}

lib/_stream_writable.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,22 +424,12 @@ function onwriteError(stream, state, sync, er, cb) {
424424
// this can emit finish, and it will always happen
425425
// after error
426426
process.nextTick(finishMaybe, stream, state);
427-
428-
// needed for duplex, fixes https://github.com/nodejs/node/issues/6083
429-
if (stream._readableState) {
430-
stream._readableState.errorEmitted = true;
431-
}
432427
stream._writableState.errorEmitted = true;
433428
stream.emit('error', er);
434429
} else {
435430
// the caller expect this to happen before if
436431
// it is async
437432
cb(er);
438-
439-
// needed for duplex, fixes https://github.com/nodejs/node/issues/6083
440-
if (stream._readableState) {
441-
stream._readableState.errorEmitted = true;
442-
}
443433
stream._writableState.errorEmitted = true;
444434
stream.emit('error', er);
445435
// this can emit finish, but finish must

lib/internal/streams/destroy.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ function destroy(err, cb) {
88
this._writableState.destroyed;
99

1010
if (readableDestroyed || writableDestroyed) {
11-
const readableErrored = this._readableState &&
12-
this._readableState.errorEmitted;
13-
const writableErrored = this._writableState &&
14-
this._writableState.errorEmitted;
15-
1611
if (cb) {
1712
cb(err);
18-
} else if (err && !readableErrored && !writableErrored) {
13+
} else if (err &&
14+
(!this._writableState || !this._writableState.errorEmitted)) {
1915
process.nextTick(emitErrorNT, this, err);
2016
}
2117
return this;
@@ -36,11 +32,6 @@ function destroy(err, cb) {
3632
this._destroy(err || null, (err) => {
3733
if (!cb && err) {
3834
process.nextTick(emitErrorAndCloseNT, this, err);
39-
40-
if (this._readableState) {
41-
this._readableState.errorEmitted = true;
42-
}
43-
4435
if (this._writableState) {
4536
this._writableState.errorEmitted = true;
4637
}
@@ -74,7 +65,6 @@ function undestroy() {
7465
this._readableState.reading = false;
7566
this._readableState.ended = false;
7667
this._readableState.endEmitted = false;
77-
this._readableState.errorEmitted = false;
7868
}
7969

8070
if (this._writableState) {

test/parallel/test-http2-client-destroy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const Countdown = require('../common/countdown');
9595
});
9696

9797
req.resume();
98+
req.on('end', common.mustCall());
9899
req.on('close', common.mustCall(() => server.close()));
99100
}));
100101
}

test/parallel/test-http2-client-onconnect-errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function runTest(test) {
101101
});
102102
}
103103

104+
req.on('end', common.mustCall());
104105
req.on('close', common.mustCall(() => {
105106
client.destroy();
106107

test/parallel/test-http2-client-stream-destroy-before-connect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ server.listen(0, common.mustCall(() => {
4545

4646
req.on('response', common.mustNotCall());
4747
req.resume();
48+
req.on('end', common.mustCall());
4849
}));

test/parallel/test-http2-compat-serverresponse-destroy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ server.listen(0, common.mustCall(() => {
6363
req.on('close', common.mustCall(() => countdown.dec()));
6464

6565
req.resume();
66+
req.on('end', common.mustCall());
6667
}
6768

6869
{
@@ -77,5 +78,6 @@ server.listen(0, common.mustCall(() => {
7778
req.on('close', common.mustCall(() => countdown.dec()));
7879

7980
req.resume();
81+
req.on('end', common.mustCall());
8082
}
8183
}));

test/parallel/test-http2-max-concurrent-streams.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ server.listen(0, common.mustCall(() => {
4545
req.on('aborted', common.mustCall());
4646
req.on('response', common.mustNotCall());
4747
req.resume();
48+
req.on('end', common.mustCall());
4849
req.on('close', common.mustCall(() => countdown.dec()));
4950
req.on('error', common.expectsError({
5051
code: 'ERR_HTTP2_STREAM_ERROR',

test/parallel/test-http2-misused-pseudoheaders.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ server.listen(0, common.mustCall(() => {
4141

4242
req.on('response', common.mustCall());
4343
req.resume();
44+
req.on('end', common.mustCall());
4445
req.on('close', common.mustCall(() => {
4546
server.close();
4647
client.close();

test/parallel/test-http2-multi-content-length.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ server.listen(0, common.mustCall(() => {
5353
// header to be set for non-payload bearing requests...
5454
const req = client.request({ 'content-length': 1 });
5555
req.resume();
56+
req.on('end', common.mustCall());
5657
req.on('close', common.mustCall(() => countdown.dec()));
5758
req.on('error', common.expectsError({
5859
code: 'ERR_HTTP2_STREAM_ERROR',

0 commit comments

Comments
 (0)