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 · nodejs/node@88b034f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/quic
    • http3.cc
  • test/parallel
    • test-quic-h3-reset-after-headers.mjs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/quic/http3.cc‎

Copy file name to clipboardExpand all lines: src/quic/http3.cc
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,14 @@ class Http3ApplicationImpl final : public Session::Application {
562562
}
563563

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

568575
bool SendHeaders(Stream& stream,
Collapse file

‎test/parallel/test-quic-h3-reset-after-headers.mjs‎

Copy file name to clipboard
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Flags: --experimental-quic --no-warnings
2+
3+
// Test: an HTTP/3 server that abandons a stream right after submitting
4+
// response headers delivers RESET_STREAM to the client, and the session
5+
// keeps working. The headers are still queued in nghttp3 when the stream
6+
// is destroyed. If nghttp3 later tries to write them, reading the body of
7+
// the removed stream fails and the whole session closes silently.
8+
9+
import { hasQuic, skip, mustCall } from '../common/index.mjs';
10+
import assert from 'node:assert';
11+
import * as fixtures from '../common/fixtures.mjs';
12+
13+
if (!hasQuic) {
14+
skip('QUIC is not enabled');
15+
}
16+
17+
const { listen, connect } = await import('node:quic');
18+
const { createPrivateKey } = await import('node:crypto');
19+
20+
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
21+
const cert = fixtures.readKey('agent1-cert.pem');
22+
23+
// RFC 9114 H3_REQUEST_CANCELLED.
24+
const H3_REQUEST_CANCELLED = 0x10cn;
25+
26+
const cases = [
27+
['resetStream() then destroy()', (stream) => {
28+
stream.resetStream(H3_REQUEST_CANCELLED);
29+
stream.destroy();
30+
}],
31+
['destroy() with a code', (stream) => {
32+
stream.onerror = () => {};
33+
stream.destroy(new Error('abandoned'), { code: H3_REQUEST_CANCELLED });
34+
}],
35+
];
36+
37+
function request(session, path) {
38+
return session.createBidirectionalStream({
39+
headers: {
40+
':method': 'GET',
41+
':path': path,
42+
':scheme': 'https',
43+
':authority': 'localhost',
44+
},
45+
});
46+
}
47+
48+
for (const [label, abandon] of cases) {
49+
const serverEndpoint = await listen(mustCall((serverSession) => {
50+
serverSession.onerror = () => {};
51+
}), {
52+
sni: { '*': { keys: [key], certs: [cert] } },
53+
onheaders: mustCall(function(headers) {
54+
// Submit response headers, then abandon the first request in the
55+
// same tick, before nghttp3 has written the headers.
56+
this.sendHeaders({ ':status': '200' }, {
57+
terminal: headers[':path'] !== '/abandon',
58+
});
59+
if (headers[':path'] === '/abandon') abandon(this);
60+
}, 2),
61+
});
62+
63+
const clientSession = await connect(serverEndpoint.address, {
64+
servername: 'localhost',
65+
verifyPeer: 'manual',
66+
});
67+
await clientSession.opened;
68+
69+
// The first request is abandoned with H3_REQUEST_CANCELLED.
70+
const abandoned = await request(clientSession, '/abandon');
71+
abandoned.onerror = () => {};
72+
const reset = Promise.withResolvers();
73+
abandoned.onreset = mustCall((error) => reset.resolve(error));
74+
const error = await reset.promise;
75+
assert.strictEqual(error?.errorCode, H3_REQUEST_CANCELLED, label);
76+
77+
// The session still works: a second request gets a response.
78+
const ok = await request(clientSession, '/ok');
79+
const status = Promise.withResolvers();
80+
ok.onheaders = mustCall((headers) => status.resolve(headers[':status']));
81+
assert.strictEqual(await status.promise, 200, label);
82+
await ok.closed;
83+
84+
await clientSession.close();
85+
await serverEndpoint.close();
86+
}

0 commit comments

Comments
0 (0)
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.