Skip to content

Commit ef992f6

Browse files
szmarczaknodejs-github-bot
authored andcommitted
stream: do not emit end on readable error
PR-URL: #39607 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c61870c commit ef992f6

12 files changed

+24
-14
lines changed

lib/internal/streams/readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ function endReadableNT(state, stream) {
13281328
debug('endReadableNT', state.endEmitted, state.length);
13291329

13301330
// Check that we didn't get one last unshift.
1331-
if (!state.errorEmitted && !state.closeEmitted &&
1331+
if (!state.errored && !state.closeEmitted &&
13321332
!state.endEmitted && state.length === 0) {
13331333
state.endEmitted = true;
13341334
stream.emit('end');

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const { getEventListeners } = require('events');
163163

164164
client.close();
165165
req.resume();
166-
req.on('end', common.mustCall());
166+
req.on('end', common.mustNotCall());
167167
req.on('close', common.mustCall(() => server.close()));
168168
}));
169169
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function runTest(test) {
102102
});
103103
}
104104

105-
req.on('end', common.mustCall());
105+
req.on('end', common.mustNotCall());
106106
req.on('close', common.mustCall(() => {
107107
client.destroy();
108108

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ server.listen(0, common.mustCall(() => {
6262
req.on('close', common.mustCall(() => countdown.dec()));
6363

6464
req.resume();
65-
req.on('end', common.mustCall());
65+
req.on('end', common.mustNotCall());
6666
}
6767

6868
{
@@ -77,6 +77,6 @@ server.listen(0, common.mustCall(() => {
7777
req.on('close', common.mustCall(() => countdown.dec()));
7878

7979
req.resume();
80-
req.on('end', common.mustCall());
80+
req.on('end', common.mustNotCall());
8181
}
8282
}));

test/parallel/test-http2-empty-frame-without-eof.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ async function main() {
3434
client.on('error', common.expectsError(expected));
3535
}
3636
stream.resume();
37-
await once(stream, 'end');
37+
await new Promise((resolve) => {
38+
stream.once('close', resolve);
39+
});
3840
client.close();
3941
}
4042
server.close();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +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());
48+
req.on('end', common.mustNotCall());
4949
req.on('close', common.mustCall(() => countdown.dec()));
5050
req.on('error', common.expectsError({
5151
code: 'ERR_HTTP2_STREAM_ERROR',

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ server.listen(0, common.mustCall(() => {
5454
// header to be set for non-payload bearing requests...
5555
const req = client.request({ 'content-length': 1 });
5656
req.resume();
57-
req.on('end', common.mustCall());
57+
req.on('end', common.mustNotCall());
5858
req.on('close', common.mustCall(() => countdown.dec()));
5959
req.on('error', common.expectsError({
6060
code: 'ERR_HTTP2_STREAM_ERROR',

test/parallel/test-http2-respond-file-fd-invalid.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ server.listen(0, () => {
4040
req.on('response', common.mustCall());
4141
req.on('error', errorCheck);
4242
req.on('data', common.mustNotCall());
43-
req.on('end', common.mustCall(() => {
43+
req.on('end', common.mustNotCall());
44+
req.on('close', common.mustCall(() => {
4445
assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
4546
client.close();
4647
server.close();

test/parallel/test-http2-respond-nghttperrors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ function runTest(test) {
8383
name: 'Error',
8484
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
8585
}));
86+
req.on('end', common.mustNotCall());
8687

8788
currentError = test;
8889
req.resume();
8990
req.end();
9091

91-
req.on('end', common.mustCall(() => {
92+
req.on('close', common.mustCall(() => {
9293
client.close();
9394

9495
if (!tests.length) {

test/parallel/test-http2-respond-with-fd-errors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,13 @@ function runTest(test) {
9191
name: 'Error',
9292
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
9393
}));
94+
req.on('end', common.mustNotCall());
9495

9596
currentError = test;
9697
req.resume();
9798
req.end();
9899

99-
req.on('end', common.mustCall(() => {
100+
req.on('close', common.mustCall(() => {
100101
client.close();
101102

102103
if (!tests.length) {

test/parallel/test-http2-server-shutdown-before-respond.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ server.on('listening', common.mustCall(() => {
3232
}));
3333
req.resume();
3434
req.on('data', common.mustNotCall());
35-
req.on('end', common.mustCall(() => server.close()));
35+
req.on('end', common.mustNotCall());
36+
req.on('close', common.mustCall(() => server.close()));
3637
}));

test/parallel/test-http2-server-socket-destroy.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if (!common.hasCrypto)
88
const assert = require('assert');
99
const h2 = require('http2');
1010
const { kSocket } = require('internal/http2/util');
11+
const { once } = require('events');
1112

1213
const server = h2.createServer();
1314

@@ -36,7 +37,7 @@ function onStream(stream) {
3637

3738
server.listen(0);
3839

39-
server.on('listening', common.mustCall(() => {
40+
server.on('listening', common.mustCall(async () => {
4041
const client = h2.connect(`http://localhost:${server.address().port}`);
4142
// The client may have an ECONNRESET error here depending on the operating
4243
// system, due mainly to differences in the timing of socket closing. Do
@@ -58,5 +59,8 @@ server.on('listening', common.mustCall(() => {
5859

5960
req.on('aborted', common.mustCall());
6061
req.resume();
61-
req.on('end', common.mustCall());
62+
63+
try {
64+
await once(req, 'end');
65+
} catch {}
6266
}));

0 commit comments

Comments
 (0)