Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(H2-#3140): abort requets upon GOAWAY #3143

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ function onHttp2SessionEnd () {
* This is the root cause of #3011
* We need to handle GOAWAY frames properly, and trigger the session close
* along with the socket right away
* Find a way to trigger the close cycle from here on.
*/
function onHTTP2GoAway (code) {
const err = new InformationalError(`HTTP/2: "GOAWAY" frame received with code ${code}`)
const err = new RequestAbortedError(`HTTP/2: "GOAWAY" frame received with code ${code}`)

// We need to trigger the close cycle right away
// We need to destroy the session and the socket
Expand All @@ -220,8 +219,7 @@ function onHTTP2GoAway (code) {
this[kClient][kOnError](err)

this.unref()
// We send the GOAWAY frame response as no error
this.destroy()

util.destroy(this[kSocket], err)
}

Expand Down
1 change: 1 addition & 0 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ function onError (client, err) {
assert(client[kPendingIdx] === client[kRunningIdx])

const requests = client[kQueue].splice(client[kRunningIdx])

for (let i = 0; i < requests.length; i++) {
const request = requests[i]
util.errorRequest(client, request, err)
Expand Down
23 changes: 12 additions & 11 deletions test/http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ test('Should support H2 GOAWAY (server-side)', async t => {

server.on('session', session => {
setTimeout(() => {
session.goaway(204)
session.goaway(0)
}, 1000)
})

Expand Down Expand Up @@ -274,7 +274,7 @@ test('Should support H2 GOAWAY (server-side)', async t => {

t.ok(url instanceof URL)
t.deepStrictEqual(disconnectClient, [client])
t.strictEqual(err.message, 'HTTP/2: "GOAWAY" frame received with code 204')
t.strictEqual(err.message, 'HTTP/2: "GOAWAY" frame received with code 0')
})

test('Should throw if bad allowH2 has been passed', async t => {
Expand Down Expand Up @@ -1427,20 +1427,21 @@ test('#3046 - GOAWAY Frame', async t => {
t.strictEqual(err.message, 'HTTP/2: "GOAWAY" frame received with code 0')
})

client.request({
const response = await client.request({
path: '/',
method: 'GET',
headers: {
'x-my-header': 'foo'
}
}, (err, response) => {
t.ifError(err)
t.strictEqual(response.headers['content-type'], 'text/plain; charset=utf-8')
t.strictEqual(response.headers['x-custom-h2'], 'hello')
t.strictEqual(response.statusCode, 200)
// We stop the sent the GOAWAY frame before the body is sent, as we received the GOAWAY frame
// before the DATA one, the body will be empty
response.body.dump()
})

t.strictEqual(response.headers['content-type'], 'text/plain; charset=utf-8')
t.strictEqual(response.headers['x-custom-h2'], 'hello')
t.strictEqual(response.statusCode, 200)

t.rejects(response.body.text.bind(response.body), {
message: 'HTTP/2: "GOAWAY" frame received with code 0',
code: 'UND_ERR_ABORTED'
})

await t.completed
Expand Down
Loading