Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/quic/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-quic-connect-first-flight-failure.mjs
Original file line number Diff line number Diff line change
@@ -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',
});
}
Loading