Skip to content

Commit e4d369e

Browse files
committed
quic: remove onSessionDestroy callback
The QuicSession can be destroyed during garbage collection and the onSessionDestroy callback was happening in the destructor. PR-URL: #34160 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 3acdd6a commit e4d369e

File tree

6 files changed

+9
-46
lines changed

6 files changed

+9
-46
lines changed

lib/internal/quic/core.js

+6-24
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,6 @@ function onSessionClose(code, family, silent, statelessReset) {
288288
this[owner_symbol][kDestroy](code, family, silent, statelessReset);
289289
}
290290

291-
// Called by the C++ internals when a QuicSession has been destroyed.
292-
// When this is called, the QuicSession is no longer usable. Removing
293-
// the handle and emitting close is the only action.
294-
// TODO(@jasnell): In the future, this will need to act differently
295-
// for QuicClientSessions when autoResume is enabled.
296-
function onSessionDestroyed() {
297-
const session = this[owner_symbol];
298-
this[owner_symbol] = undefined;
299-
300-
if (session) {
301-
session[kSetHandle]();
302-
process.nextTick(emit.bind(session, 'close'));
303-
}
304-
}
305-
306291
// Used only within the onSessionClientHello function. Invoked
307292
// to complete the client hello process.
308293
function clientHelloCallback(err, ...args) {
@@ -558,7 +543,6 @@ setCallbacks({
558543
onSessionCert,
559544
onSessionClientHello,
560545
onSessionClose,
561-
onSessionDestroyed,
562546
onSessionHandshake,
563547
onSessionKeylog,
564548
onSessionQlog,
@@ -1908,28 +1892,26 @@ class QuicSession extends EventEmitter {
19081892
this.removeListener('newListener', onNewListener);
19091893
this.removeListener('removeListener', onRemoveListener);
19101894

1911-
// If we are destroying with an error, schedule the
1912-
// error to be emitted on process.nextTick.
1913-
if (error) process.nextTick(emit.bind(this, 'error', error));
1914-
19151895
const handle = this[kHandle];
1916-
this[kHandle] = undefined;
1917-
1896+
this[kHandle] = undefined
19181897
if (handle !== undefined) {
19191898
// Copy the stats for use after destruction
19201899
state.stats = new BigInt64Array(handle.stats);
19211900
state.idleTimeout = this[kInternalState].state.idleTimeout;
19221901

19231902
// Destroy the underlying QuicSession handle
19241903
handle.destroy(state.closeCode, state.closeFamily);
1925-
} else {
1926-
process.nextTick(emit.bind(this, 'close'));
19271904
}
19281905

19291906
// Remove the QuicSession JavaScript object from the
19301907
// associated QuicSocket.
19311908
state.socket[kRemoveSession](this);
19321909
state.socket = undefined;
1910+
1911+
// If we are destroying with an error, schedule the
1912+
// error to be emitted on process.nextTick.
1913+
if (error) process.nextTick(emit.bind(this, 'error', error));
1914+
process.nextTick(emit.bind(this, 'close'));
19331915
}
19341916

19351917
// For server QuicSession instances, true if earlyData is

src/env.h

-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ constexpr size_t kFsStatsBufferLength =
454454
V(quic_on_session_cert_function, v8::Function) \
455455
V(quic_on_session_client_hello_function, v8::Function) \
456456
V(quic_on_session_close_function, v8::Function) \
457-
V(quic_on_session_destroyed_function, v8::Function) \
458457
V(quic_on_session_handshake_function, v8::Function) \
459458
V(quic_on_session_keylog_function, v8::Function) \
460459
V(quic_on_session_path_validation_function, v8::Function) \

src/quic/node_quic.cc

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void QuicSetCallbacks(const FunctionCallbackInfo<Value>& args) {
5959
SETFUNCTION("onSessionCert", session_cert);
6060
SETFUNCTION("onSessionClientHello", session_client_hello);
6161
SETFUNCTION("onSessionClose", session_close);
62-
SETFUNCTION("onSessionDestroyed", session_destroyed);
6362
SETFUNCTION("onSessionHandshake", session_handshake);
6463
SETFUNCTION("onSessionKeylog", session_keylog);
6564
SETFUNCTION("onSessionUsePreferredAddress", session_use_preferred_address);

src/quic/node_quic_session.cc

+1-16
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ void QuicSessionListener::OnStreamReset(
289289
previous_listener_->OnStreamReset(stream_id, app_error_code);
290290
}
291291

292-
void QuicSessionListener::OnSessionDestroyed() {
293-
if (previous_listener_ != nullptr)
294-
previous_listener_->OnSessionDestroyed();
295-
}
296-
297292
void QuicSessionListener::OnSessionClose(QuicError error, int flags) {
298293
if (previous_listener_ != nullptr)
299294
previous_listener_->OnSessionClose(error, flags);
@@ -509,16 +504,6 @@ void JSQuicSessionListener::OnStreamReset(
509504
argv);
510505
}
511506

512-
void JSQuicSessionListener::OnSessionDestroyed() {
513-
Environment* env = session()->env();
514-
HandleScope scope(env->isolate());
515-
Context::Scope context_scope(env->context());
516-
// Emit the 'close' event in JS. This needs to happen after destroying the
517-
// connection, because doing so also releases the last qlog data.
518-
session()->MakeCallback(
519-
env->quic_on_session_destroyed_function(), 0, nullptr);
520-
}
521-
522507
void JSQuicSessionListener::OnSessionClose(QuicError error, int flags) {
523508
Environment* env = session()->env();
524509
HandleScope scope(env->isolate());
@@ -1412,6 +1397,7 @@ QuicSession::QuicSession(
14121397
QuicCID(),
14131398
options,
14141399
preferred_address_strategy) {
1400+
set_wrapped();
14151401
InitClient(
14161402
local_addr,
14171403
remote_addr,
@@ -1472,7 +1458,6 @@ QuicSession::~QuicSession() {
14721458
CHECK(!Ngtcp2CallbackScope::InNgtcp2CallbackScope(this));
14731459

14741460
QuicSessionListener* listener_ = listener();
1475-
listener_->OnSessionDestroyed();
14761461
if (listener_ == listener())
14771462
RemoveListener(listener_);
14781463

src/quic/node_quic_session.h

-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ class QuicSessionListener {
251251
virtual void OnStreamReset(
252252
int64_t stream_id,
253253
uint64_t app_error_code);
254-
virtual void OnSessionDestroyed();
255254
virtual void OnSessionClose(
256255
QuicError error,
257256
int flags = SESSION_CLOSE_FLAG_NONE);
@@ -299,7 +298,6 @@ class JSQuicSessionListener : public QuicSessionListener {
299298
void OnStreamReset(
300299
int64_t stream_id,
301300
uint64_t app_error_code) override;
302-
void OnSessionDestroyed() override;
303301
void OnSessionClose(
304302
QuicError error,
305303
int flags = SESSION_CLOSE_FLAG_NONE) override;

test/parallel/test-quic-maxconnectionsperhost.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ const kALPN = 'zzz';
7777
countdown.dec();
7878
// Shutdown the remaining open sessions.
7979
setImmediate(common.mustCall(() => {
80-
for (const req of sessions)
81-
req.close();
80+
for (const req of sessions)
81+
req.close();
8282
}));
8383
}));
8484

0 commit comments

Comments
 (0)