Skip to content

Commit cef9097

Browse files
committed
http2: do not emit our own close emit in Http2Stream
Streams were recently updated to emit their own close event. The Http2Stream was an exception because it included the close argument with the close event. Refactor that to use the built in close. PR-URL: #19451 Reviewed-By: Matteo Collina <[email protected]>
1 parent ab75548 commit cef9097

9 files changed

+18
-21
lines changed

doc/api/http2.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Immediately terminates the `Http2Session` and the associated `net.Socket` or
335335
`tls.TLSSocket`.
336336

337337
Once destroyed, the `Http2Session` will emit the `'close'` event. If `error`
338-
is not undefined, an `'error'` event will be emitted immediately after the
338+
is not undefined, an `'error'` event will be emitted immediately before the
339339
`'close'` event.
340340

341341
If there are any remaining open `Http2Streams` associated with the
@@ -816,9 +816,9 @@ added: v8.4.0
816816
The `'close'` event is emitted when the `Http2Stream` is destroyed. Once
817817
this event is emitted, the `Http2Stream` instance is no longer usable.
818818

819-
The listener callback is passed a single argument specifying the HTTP/2 error
820-
code specified when closing the stream. If the code is any value other than
821-
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will also be emitted.
819+
The HTTP/2 error code used when closing the stream can be retrieved using
820+
the `http2stream.rstCode` property. If the code is any value other than
821+
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will have also been emitted.
822822

823823
#### Event: 'error'
824824
<!-- YAML

lib/internal/http2/core.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,6 @@ class Http2Stream extends Duplex {
15031503
constructor(session, options) {
15041504
options.allowHalfOpen = true;
15051505
options.decodeStrings = false;
1506-
options.emitClose = false;
15071506
super(options);
15081507
this[async_id_symbol] = -1;
15091508

@@ -1888,9 +1887,7 @@ class Http2Stream extends Duplex {
18881887
// will destroy if it has been closed and there are no other open or
18891888
// pending streams.
18901889
session[kMaybeDestroy]();
1891-
process.nextTick(emit, this, 'close', code);
18921890
callback(err);
1893-
18941891
}
18951892
// The Http2Stream can be destroyed if it has closed and if the readable
18961893
// side has received the final chunk.

test/parallel/test-http2-client-rststream-before-connect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ server.listen(0, common.mustCall(() => {
4949
// Second call doesn't do anything.
5050
req.close(closeCode + 1);
5151

52-
req.on('close', common.mustCall((code) => {
52+
req.on('close', common.mustCall(() => {
5353
assert.strictEqual(req.destroyed, true);
54-
assert.strictEqual(code, closeCode);
54+
assert.strictEqual(req.rstCode, closeCode);
5555
server.close();
5656
client.close();
5757
}));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ server.listen(0, common.mustCall(() => {
3636
message: 'test'
3737
}));
3838

39-
req.on('close', common.mustCall((code) => {
39+
req.on('close', common.mustCall(() => {
40+
assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
4041
assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
41-
assert.strictEqual(code, NGHTTP2_INTERNAL_ERROR);
4242
server.close();
4343
client.close();
4444
}));

test/parallel/test-http2-options-max-reserved-streams.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ server.on('stream', common.mustCall((stream) => {
3737
pushedStream.respond();
3838
pushedStream.on('aborted', common.mustCall());
3939
pushedStream.on('error', common.mustNotCall());
40-
pushedStream.on('close', common.mustCall((code) => {
41-
assert.strictEqual(code, 8);
40+
pushedStream.on('close', common.mustCall(() => {
41+
assert.strictEqual(pushedStream.rstCode, 8);
4242
countdown.dec();
4343
}));
4444
}));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ server.on('listening', common.mustCall(() => {
2828
const client = h2.connect(`http://localhost:${server.address().port}`);
2929
const req = client.request();
3030
req.on('headers', common.mustNotCall());
31-
req.on('close', common.mustCall((code) => {
32-
assert.strictEqual(h2.constants.NGHTTP2_NO_ERROR, code);
31+
req.on('close', common.mustCall(() => {
32+
assert.strictEqual(h2.constants.NGHTTP2_NO_ERROR, req.rstCode);
3333
server.close();
3434
client.close();
3535
}));

test/parallel/test-http2-server-rst-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ server.listen(0, common.mustCall(() => {
5050
':method': 'POST',
5151
'rstcode': test[0]
5252
});
53-
req.on('close', common.mustCall((code) => {
54-
assert.strictEqual(code, test[0]);
53+
req.on('close', common.mustCall(() => {
54+
assert.strictEqual(req.rstCode, test[0]);
5555
countdown.dec();
5656
}));
5757
req.on('aborted', common.mustCall());

test/parallel/test-http2-too-large-headers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ server.listen(0, common.mustCall(() => {
2222
type: Error,
2323
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
2424
}));
25-
req.on('close', common.mustCall((code) => {
26-
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);
25+
req.on('close', common.mustCall(() => {
26+
assert.strictEqual(req.rstCode, NGHTTP2_ENHANCE_YOUR_CALM);
2727
server.close();
2828
client.close();
2929
}));

test/parallel/test-http2-too-many-headers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ server.listen(0, common.mustCall(() => {
2525
type: Error,
2626
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
2727
}));
28-
req.on('close', common.mustCall((code) => {
29-
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);
28+
req.on('close', common.mustCall(() => {
29+
assert.strictEqual(req.rstCode, NGHTTP2_ENHANCE_YOUR_CALM);
3030
server.close();
3131
client.close();
3232
}));

0 commit comments

Comments
 (0)