Skip to content

Commit 0a64b40

Browse files
committed
http2: add edge case to GOWAY request
1 parent 2f7920c commit 0a64b40

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

doc/api/http2.md

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

925+
When a `ClientHttp2Session` is first created, the socket may not yet be
926+
connected. if `clienthttp2session.request()` is called during this time, the
927+
actual request will be deferred until the socket is ready to go.
928+
If the `session` is closed before the actual request be executed, an
929+
`ERR_HTTP2_GOAWAY_SESSION` is thrown.
930+
925931
This method is only available if `http2session.type` is equal to
926932
`http2.constants.NGHTTP2_SESSION_CLIENT`.
927933

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
setTimeout(() => {
22+
client.close()
23+
}, 1);
24+
});

0 commit comments

Comments
 (0)