GeezerVison is showing github.com — fix(h2): do not replay a request whose response already started after GOAWAY by kjsik11 · Pull Request #5788 · nodejs/undici
Conversation
kjsik11
commented
Sep 8, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
This relates to...
Rationale
The onHttp2SessionGoAway() never check the response already started.
if the peer server broke the rules(RFC 9113 §8.7), and send a lastStreamId lower than a stream it already responded,undici resend the in-flight request.
Repro — client.request() and fetch(), main vs this PR
Save repro.mjs in the root, run with node --no-warnings repro.mjs.
// Run from the undici repository root: node --no-warnings repro.mjs
// Shows how the second request settles under client.request() and fetch() when
// the server sends a GOAWAY whose lastStreamID is below a stream it has
// already responded on.
import { readFileSync } from 'node:fs'
import { createSecureServer, constants } from 'node:http2'
import { once } from 'node:events'
import { Client, fetch } from './index.js'
const SETTLE_TIMEOUT = 3000
const server = createSecureServer({
key: readFileSync('./test/fixtures/key.pem'),
cert: readFileSync('./test/fixtures/cert.pem')
})
// On main the replay leaves a stream nobody closes, so track sessions to tear
// the server down explicitly at the end.
const sessions = new Set()
server.on('session', session => {
sessions.add(session)
session.once('close', () => sessions.delete(session))
})
let secondHits = 0
server.on('stream', (stream, headers) => {
stream.on('error', () => {})
if (headers[':path'] === '/first') {
stream.respond({ ':status': 200 })
stream.end('ok')
return
}
// /second: send the response headers, keep the stream open, then send a
// GOAWAY naming stream 1 as last-processed even though stream 3 was answered.
secondHits++
stream.respond({ ':status': 200 })
setTimeout(() => stream.session.goaway(constants.NGHTTP2_NO_ERROR, 1), 50)
})
await once(server.listen(0), 'listening')
const origin = `https://localhost:${server.address().port}`
const options = { allowH2: true, connect: { rejectUnauthorized: false } }
// Describes how a body promise settles, or reports a hang after SETTLE_TIMEOUT.
function describe (bodyPromise) {
let timer
const hang = new Promise(resolve => {
timer = setTimeout(() => resolve(`no settle within ${SETTLE_TIMEOUT}ms (hang)`), SETTLE_TIMEOUT)
})
const settled = bodyPromise.then(
text => `resolved ${JSON.stringify(text)}`,
err => `rejected ${err.code ?? err.name}${err.cause ? ` (cause ${err.cause.code})` : ''}`
)
return Promise.race([settled, hang]).finally(() => clearTimeout(timer))
}
// 1. client.request()
{
secondHits = 0
const client = new Client(origin, options)
await (await client.request({ path: '/first', method: 'GET' })).body.text()
const res = await client.request({ path: '/second', method: 'GET' })
console.log(`client.request(): ${await describe(res.body.text())}; server handled /second ${secondHits}x`)
await client.destroy()
}
// 2. fetch()
{
secondHits = 0
const client = new Client(origin, options)
await (await fetch(`${origin}/first`, { dispatcher: client })).text()
const res = await fetch(`${origin}/second`, { dispatcher: client })
console.log(`fetch(): ${await describe(res.text())}; server handled /second ${secondHits}x`)
await client.destroy()
}
for (const session of sessions) session.destroy()
server.close()
main:
client.request(): rejected ERR_ASSERTION; server handled /second 1x
fetch(): no settle within 3000ms (hang); server handled /second 2x
This PR:
client.request(): rejected UND_ERR_INFO; server handled /second 1x
fetch(): rejected TypeError (cause UND_ERR_INFO); server handled /second 1x
Changes
lib/dispatcher/client-h2.js: read the stream's responseReceived and skip resend when the response started
test/http2-goaway.js: checks that the req failed and is not resent with the invalid GoAway with lower lastStreamId
Features
N/A
Bug Fixes
- Now h2 request isn't resend with already started response. and it fails with the
GoAway error
Breaking Changes and Deprecations
N/A
Test results (Node 24.20.0)
npm run lint clean
test/http2-goaway.js 7/7
test:h2:core (test/http2*.js + test/h2*.js) 110/110
test/websocket/**/*.js (npm run test:websocket) 147/147
The new test failed on main and passes with this pr
Assisted by: claude code
Status
- I have read and agreed to the Developer's Certificate of Origin
- Tested
- [S] Benchmarked (optional — error path only, N/A)
- [S] Documented (no public API change)
- Review ready
- In review
- Merge ready
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.51%. Comparing base (b73952a) to head (791bd9a).
⚠️ Report is 2 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #5788 +/- ##
==========================================
- Coverage 93.51% 93.51% -0.01%
==========================================
Files 110 110
Lines 39359 39367 +8
==========================================
+ Hits 36808 36815 +7
- Misses 2551 2552 +1
☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Sep 21, 2026
Reviewers
mcollina
mcollina approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|