From ddef6bbcb8ead52acb46787766ad4abf182c58a3 Mon Sep 17 00:00:00 2001 From: Rafael Silva Date: Sun, 6 Mar 2022 15:23:34 -0300 Subject: [PATCH] http2: add edge case to GOAWAY request PR-URL: https://github.com/nodejs/node/pull/42190 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- doc/api/http2.md | 6 +++++ .../test-http2-goaway-delayed-request.js | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/parallel/test-http2-goaway-delayed-request.js diff --git a/doc/api/http2.md b/doc/api/http2.md index bd6ee80bf6c0e3..d213572f873561 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -935,6 +935,12 @@ For HTTP/2 Client `Http2Session` instances only, the `http2session.request()` creates and returns an `Http2Stream` instance that can be used to send an HTTP/2 request to the connected server. +When a `ClientHttp2Session` is first created, the socket may not yet be +connected. if `clienthttp2session.request()` is called during this time, the +actual request will be deferred until the socket is ready to go. +If the `session` is closed before the actual request be executed, an +`ERR_HTTP2_GOAWAY_SESSION` is thrown. + This method is only available if `http2session.type` is equal to `http2.constants.NGHTTP2_SESSION_CLIENT`. diff --git a/test/parallel/test-http2-goaway-delayed-request.js b/test/parallel/test-http2-goaway-delayed-request.js new file mode 100644 index 00000000000000..7afadbe80186ee --- /dev/null +++ b/test/parallel/test-http2-goaway-delayed-request.js @@ -0,0 +1,22 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const http2 = require('http2'); + +const server = http2.createServer(); + +server.listen(0, () => { + const client = http2.connect(`http://localhost:${server.address().port}`); + client.on('close', common.mustCall(() => { + server.close(); + })); + + // The client.close() is executed before the socket is able to make request + const stream = client.request(); + stream.on('error', common.expectsError({ code: 'ERR_HTTP2_GOAWAY_SESSION' })); + + setImmediate(() => client.close()); +});