mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
quic: fix fix h3 session close on early str. destr
This fixes the fix from the PR #67446. The previous PR did not allow already submitted data, such as a Webtransport close capsule to be transmitted to ngtcp2. This PR instead uses the nullptr reader, to detect a closed stream and signals eof. This is of course only an intermediate solution, instead quic RESET_AT semantics are a far better solution. Signed-off-by: Marten Richter <marten.richter@freenet.de> PR-URL: https://github.com/nodejs/node/pull/67706 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
1 parent
4d544ead13
commit
32d410cb10
2 files changed
+87
-6
No files matched your search
+8
-6
@@ -563,12 +563,9 @@ class Http3ApplicationImpl final : public Session::Application {
|
||||
|
||||
void StreamRemoved(stream_id id) override {
|
||||
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);
|
||||
// Once the Stream is gone, nothing can supply its body data.
|
||||
// So the on_read_data_callback should detect the nullptr user_data
|
||||
// and signal EOF.
|
||||
nghttp3_conn_set_stream_user_data(*this, id, nullptr);
|
||||
}
|
||||
|
||||
@@ -1202,6 +1199,11 @@ class Http3ApplicationImpl final : public Session::Application {
|
||||
CHECK_NOT_NULL(ptr);
|
||||
auto& app = *ptr;
|
||||
NgHttp3CallbackScope scope(&app.session());
|
||||
if (stream_user_data == nullptr) {
|
||||
// stream is gone on js side, we exit silently
|
||||
*pflags |= NGHTTP3_DATA_FLAG_EOF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BaseObjectPtr<Stream> stream(static_cast<Stream*>(stream_user_data));
|
||||
if (!stream) [[unlikely]] {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Flags: --experimental-quic --no-warnings
|
||||
|
||||
// Test: an HTTP/3 server that submits non-terminal response headers and then
|
||||
// destroys the stream without an error code still delivers the headers and
|
||||
// ends the stream cleanly, and the session keeps working. Nothing resets the
|
||||
// QUIC stream here, so nghttp3 must flush the queued headers and send FIN
|
||||
// after the stream is removed on the JS side.
|
||||
|
||||
import { hasQuic, skip, mustCall, mustNotCall } 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');
|
||||
|
||||
function request(session, path) {
|
||||
return session.createBidirectionalStream({
|
||||
headers: {
|
||||
':method': 'GET',
|
||||
':path': path,
|
||||
':scheme': 'https',
|
||||
':authority': 'localhost',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onerror = () => {};
|
||||
}), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
onheaders: mustCall(function(headers) {
|
||||
const abandon = headers[':path'] === '/abandon';
|
||||
this.sendHeaders({ ':status': '200' }, { terminal: !abandon });
|
||||
if (abandon) {
|
||||
// Destroy in the same tick, before nghttp3 has written the headers,
|
||||
// and without an error code, so no RESET_STREAM is sent.
|
||||
this.onerror = () => {};
|
||||
this.destroy();
|
||||
}
|
||||
}, 2),
|
||||
});
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
servername: 'localhost',
|
||||
verifyPeer: 'manual',
|
||||
});
|
||||
await clientSession.opened;
|
||||
|
||||
// The abandoned request still gets its headers and a clean end of stream.
|
||||
const abandoned = await request(clientSession, '/abandon');
|
||||
abandoned.onreset = mustNotCall();
|
||||
const abandonedStatus = Promise.withResolvers();
|
||||
abandoned.onheaders = mustCall((headers) => {
|
||||
abandonedStatus.resolve(headers[':status']);
|
||||
});
|
||||
assert.strictEqual(await abandonedStatus.promise, 200);
|
||||
let bytes = 0;
|
||||
for await (const chunks of abandoned) {
|
||||
for (const chunk of chunks) bytes += chunk.byteLength;
|
||||
}
|
||||
assert.strictEqual(bytes, 0);
|
||||
await abandoned.closed;
|
||||
|
||||
// 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);
|
||||
await ok.closed;
|
||||
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
Reference in new issue
Block a user