Skip to content

Commit 1de8087

Browse files
RafaelGSSsxa
authored andcommitted
http2: add edge case to GOAWAY request
PR-URL: #42190 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 555da9b commit 1de8087

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

doc/api/http2.md

+6
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ For HTTP/2 Client `Http2Session` instances only, the `http2session.request()`
939939
creates and returns an `Http2Stream` instance that can be used to send an
940940
HTTP/2 request to the connected server.
941941

942+
When a `ClientHttp2Session` is first created, the socket may not yet be
943+
connected. if `clienthttp2session.request()` is called during this time, the
944+
actual request will be deferred until the socket is ready to go.
945+
If the `session` is closed before the actual request be executed, an
946+
`ERR_HTTP2_GOAWAY_SESSION` is thrown.
947+
942948
This method is only available if `http2session.type` is equal to
943949
`http2.constants.NGHTTP2_SESSION_CLIENT`.
944950

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
const http2 = require('http2');
8+
9+
const server = http2.createServer();
10+
11+
server.listen(0, () => {
12+
const client = http2.connect(`http://localhost:${server.address().port}`);
13+
client.on('close', common.mustCall(() => {
14+
server.close();
15+
}));
16+
17+
// The client.close() is executed before the socket is able to make request
18+
const stream = client.request();
19+
stream.on('error', common.expectsError({ code: 'ERR_HTTP2_GOAWAY_SESSION' }));
20+
21+
setImmediate(() => client.close());
22+
});

0 commit comments

Comments
 (0)