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 — quic: fix h3 session close on early stream destroy by Ethan-Arrowood · Pull Request #67446 · nodejs/node

quic: fix h3 session close on early stream destroy #67446

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.

Sign up for GitHub

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

Merged
nodejs-github-bot merged 1 commit into nodejs:main from Ethan-Arrowood:quic-h3-reset-after-headers
Nov 19, 2026
+94 −1
Merged

quic: fix h3 session close on early stream destroy #67446

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
d51bf3e
quic: fix h3 session close on early stream destroy
Ethan-Arrowood Nov 12, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view
quic: fix h3 session close on early stream destroy
If the stream is destroyed right after sendHeaders(), nghttp3 still has
the response headers queued. On the next write it asks for the removed
stream's body, the read callback fails, and the whole session closes
without notifying the peer.

In an HTTP/3 session, before clearing nghttp3's pointer to a stream when
the stream is destroyed, shut down nghttp3's writes for that stream so
that other requests can continue to complete.

Assisted-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ethan Arrowood <[email protected]>
  • Loading branch information

Uh oh!

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

@Ethan-Arrowood
Ethan-Arrowood committed Nov 12, 2026
commit d51bf3e934e0472eed08c531fc9cbe5aeb3137f7

There are no files selected for viewing

9 changes: 8 additions & 1 deletion 9 src/quic/http3.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,14 @@ class Http3ApplicationImpl final : public Session::Application {
}

void StreamRemoved(stream_id id) override {
if (conn_) nghttp3_conn_set_stream_user_data(*this, id, nullptr);
if (!conn_) return;
// Once the Stream is gone, nothing can supply its body data. Stop
// nghttp3 from writing to it. Otherwise a response whose headers were
// submitted but not yet sent makes nghttp3 call on_read_data_callback
// for a stream that no longer exists, which fails and closes the
// whole session.
nghttp3_conn_shutdown_stream_write(*this, id);
nghttp3_conn_set_stream_user_data(*this, id, nullptr);
}

bool SendHeaders(Stream& stream,
Expand Down
86 changes: 86 additions & 0 deletions 86 test/parallel/test-quic-h3-reset-after-headers.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Flags: --experimental-quic --no-warnings

// Test: an HTTP/3 server that abandons a stream right after submitting
// response headers delivers RESET_STREAM to the client, and the session
// keeps working. The headers are still queued in nghttp3 when the stream
// is destroyed. If nghttp3 later tries to write them, reading the body of
// the removed stream fails and the whole session closes silently.

import { hasQuic, skip, mustCall } from '../common/index.mjs';
import assert from 'node:assert';
import * as fixtures from '../common/fixtures.mjs';

if (!hasQuic) {
skip('QUIC is not enabled');
}

const { listen, connect } = await import('node:quic');
const { createPrivateKey } = await import('node:crypto');

const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
const cert = fixtures.readKey('agent1-cert.pem');

// RFC 9114 H3_REQUEST_CANCELLED.
const H3_REQUEST_CANCELLED = 0x10cn;

const cases = [
['resetStream() then destroy()', (stream) => {
stream.resetStream(H3_REQUEST_CANCELLED);
stream.destroy();
}],
['destroy() with a code', (stream) => {
stream.onerror = () => {};
stream.destroy(new Error('abandoned'), { code: H3_REQUEST_CANCELLED });
}],
];

function request(session, path) {
return session.createBidirectionalStream({
headers: {
':method': 'GET',
':path': path,
':scheme': 'https',
':authority': 'localhost',
},
});
}

for (const [label, abandon] of cases) {
const serverEndpoint = await listen(mustCall((serverSession) => {
serverSession.onerror = () => {};
}), {
sni: { '*': { keys: [key], certs: [cert] } },
onheaders: mustCall(function(headers) {
// Submit response headers, then abandon the first request in the
// same tick, before nghttp3 has written the headers.
this.sendHeaders({ ':status': '200' }, {
terminal: headers[':path'] !== '/abandon',
});
if (headers[':path'] === '/abandon') abandon(this);
}, 2),
});

const clientSession = await connect(serverEndpoint.address, {
servername: 'localhost',
verifyPeer: 'manual',
});
await clientSession.opened;

// The first request is abandoned with H3_REQUEST_CANCELLED.
const abandoned = await request(clientSession, '/abandon');
abandoned.onerror = () => {};
const reset = Promise.withResolvers();
abandoned.onreset = mustCall((error) => reset.resolve(error));
const error = await reset.promise;
assert.strictEqual(error?.errorCode, H3_REQUEST_CANCELLED, label);

// The session still works: a second request gets a response.
const ok = await request(clientSession, '/ok');
const status = Promise.withResolvers();
ok.onheaders = mustCall((headers) => status.resolve(headers[':status']));
assert.strictEqual(await status.promise, 200, label);
await ok.closed;

await clientSession.close();
await serverEndpoint.close();
}
Loading
Oops, something went wrong.

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.
You are visitor 01402792 — 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.