Skip to content
Draft
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
2 changes: 1 addition & 1 deletion lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function onHttp2SendPing (session) {

function onPing (err, duration) {
const client = this[kClient]
const socket = this[kClient]
const socket = this[kSocket]

if (err != null) {
const error = new InformationalError(`HTTP/2: "PING" errored - type ${err.message}`)
Expand Down
95 changes: 95 additions & 0 deletions test/http2-late-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

const connectH2 = require('../lib/dispatcher/client-h2')
const Request = require('../lib/core/request')
const { setTimeout: sleep } = require('node:timers/promises')

const {
kUrl,
kSocket,
kError,
kMaxConcurrentStreams,
kHTTP2InitialWindowSize,
kHTTP2ConnectionWindowSize,
Expand Down Expand Up @@ -160,3 +163,95 @@

await t.completed
})

test('Should set kError on socket when PING fails', async (t) => {

Check failure on line 167 in test/http2-late-data.js

View workflow job for this annotation

GitHub Actions / Test with Node.js 22 on ubuntu-latest with WASM SIMD disabled / Test with Node.js 22 on ubuntu-latest

Should set kError on socket when PING fails

AssertionError [ERR_ASSERTION]: The plan was not completed 3 !== 2 at TestContext.autoEnd (/home/runner/work/undici/undici/node_modules/@matteo.collina/tspl/tspl.js:25:14) at TestHook.runInAsyncScope (node:async_hooks:214:14) at TestHook.run (node:internal/test_runner/test:1047:25) at TestHook.run (node:internal/test_runner/test:1354:18) at TestHook.run (node:internal/util:569:20) at Test.runHook (node:internal/test_runner/test:965:20) at after (node:internal/test_runner/test:1005:20) at Test.run (node:internal/test_runner/test:1070:13) at async Test.processPendingSubtests (node:internal/test_runner/test:744:7) { generatedMessage: false, code: 'ERR_ASSERTION', actual: 3, expected: 2, operator: 'strictEqual', diff: 'simple' }
t = tspl(t, { plan: 2 })

const http2 = require('node:http2')
const originalConnect = http2.connect

class FakeSocket extends EventEmitter {
constructor () {
super()
this.destroyed = false
}

destroy () {
this.destroyed = true
return this
}

ref () {}
unref () {}
}

class FakeSession extends EventEmitter {
constructor () {
super()
this.closed = false
this.destroyed = false
}

request () { return new EventEmitter() }

close () {
this.closed = true
}

destroy () {
this.destroyed = true
}

ref () {}
unref () {}
ping (cb) {
cb(new Error('ping timeout'), null)
}
}

const session = new FakeSession()

http2.connect = function () {
return session
}

after(() => {
http2.connect = originalConnect
})

const socket = new FakeSocket()

const client = {
[kUrl]: new URL('https://localhost'),
[kSocket]: null,
[kMaxConcurrentStreams]: 100,
[kHTTP2InitialWindowSize]: null,
[kHTTP2ConnectionWindowSize]: null,
[kBodyTimeout]: 30_000,
[kStrictContentLength]: true,
[kQueue]: [],
[kRunningIdx]: 0,
[kPendingIdx]: 0,
[kRunning]: 0,
[kPingInterval]: 100,
[kOnError] (err) {
t.ok(err.message.includes('PING'), 'error should be a PING error')
},
[kResume] () {},
emit () {},
destroyed: false
}

connectH2(client, socket)

// Wait for the ping interval to fire
await sleep(200)

// With the bug, kError would be set on client instead of socket
t.ok(socket[kError] != null, 'kError should be set on the socket')

// Clean up the interval
session.closed = true

await t.completed
})
Loading