mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
quic: fix abort on handshake failure in connect()
Endpoint::Connect() marked the session as wrapped before sending the first flight, while JavaScript had no QuicSession for it yet. If the session closed during that send, for example with ciphers: '', nothing called destroy() and the CHECK in Session::EmitClose() aborted the process. Send the first flight before marking the session as wrapped, so connect() rejects with ERR_QUIC_CONNECTION_FAILED instead. Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67617 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
This commit is contained in:
1 parent
6abd8c49e3
commit
10394eea40
2 files changed
+30
-2
No files matched your search
@@ -1268,11 +1268,18 @@ BaseObjectPtr<Session> Endpoint::Connect(
|
||||
return {};
|
||||
}
|
||||
|
||||
AddSession(config.scid, session);
|
||||
|
||||
// Send the first flight before marking the session as wrapped. If the
|
||||
// session closes during that send (no usable cipher suite or group, an
|
||||
// expired handshake timeout), FinishClose() has to destroy it directly
|
||||
// instead of calling into JavaScript, which has no QuicSession for it yet.
|
||||
{ Session::SendPendingDataScope send_scope(session); }
|
||||
if (session->is_destroyed()) return {};
|
||||
|
||||
// Marking a session as "wrapped" means that the reference has been
|
||||
// (or will be) passed out to JavaScript.
|
||||
Session::SendPendingDataScope send_scope(session);
|
||||
session->set_wrapped();
|
||||
AddSession(config.scid, session);
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Flags: --experimental-quic --no-warnings
|
||||
|
||||
// Test: connect() rejects when the session closes during the first flight.
|
||||
|
||||
import { hasQuic, skip } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
|
||||
const { connect } = await import('../common/quic.mjs');
|
||||
|
||||
// An empty list leaves the ClientHello without a cipher suite or a group, and
|
||||
// a handshakeTimeout of 0 has already expired once the first flight is out.
|
||||
const cases = [{ ciphers: '' }, { groups: '' }, { handshakeTimeout: 0 }];
|
||||
for (const options of cases) {
|
||||
await assert.rejects(connect('127.0.0.1:1', options), {
|
||||
code: 'ERR_QUIC_CONNECTION_FAILED',
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user