GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@kjsik11 kjsik11 commented Sep 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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 reactions
@kjsik11
fix(h2): do not replay a started response after GOAWAY
791bd9a
@codecov-commenter

codecov-commenter commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

metcoder95
metcoder95 approved these changes Sep 10, 2026
View reviewed changes
mcollina
mcollina approved these changes Sep 13, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina
mcollina merged commit 4f672b4 into nodejs:main Sep 13, 2026
38 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Sep 14, 2026
[Release] v8.11.0 #5821
Closed
@kjsik11
kjsik11 deleted the fix/h2-goaway-replay-after-response-started branch September 17, 2026 01:04
This was referenced Sep 21, 2026
[Release] v8.11.0 #5848
Closed
[Release] v8.11.0 #5849
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@metcoder95 metcoder95 metcoder95 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

4 participants

@kjsik11 @codecov-commenter @mcollina @metcoder95
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.