Skip to content

Commit acd7d97

Browse files
address comments
1 parent 2582654 commit acd7d97

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

src/cmap/connection_pool.ts

+12-26
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
415415
*/
416416
clear(options: { serviceId?: ObjectId; interruptInUseConnections?: boolean } = {}): void {
417417
const { serviceId } = options;
418-
const interruptInUseConnections = options.interruptInUseConnections ?? false;
419418
if (this.closed) {
420419
return;
421420
}
@@ -438,10 +437,9 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
438437
);
439438
return;
440439
}
441-
442-
const oldGeneration = this[kGeneration];
443-
444440
// handle non load-balanced case
441+
const interruptInUseConnections = options.interruptInUseConnections ?? false;
442+
const oldGeneration = this[kGeneration];
445443
this[kGeneration] += 1;
446444
const alreadyPaused = this[kPoolState] === PoolState.paused;
447445
this[kPoolState] = PoolState.paused;
@@ -455,7 +453,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
455453
}
456454

457455
process.nextTick(() =>
458-
this.pruneConnections({ minGeneration: oldGeneration, interruptInUseConnections })
456+
this.interruptInUseConnections({ interruptInUseConnections, minGeneration: oldGeneration })
459457
);
460458

461459
this.processWaitQueue();
@@ -468,41 +466,29 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
468466
* Only connections where `connection.generation <= minGeneration` are killed. Connections are closed with a
469467
* resumable PoolClearedOnNetworkTimeoutError.
470468
*/
471-
private pruneConnections({
469+
private interruptInUseConnections({
472470
interruptInUseConnections,
473471
minGeneration
474472
}: {
475473
interruptInUseConnections: boolean;
476474
minGeneration: number;
477475
}) {
478-
this[kConnections].prune(connection => {
476+
if (!interruptInUseConnections) {
477+
return;
478+
}
479+
for (const connection of this[kCheckedOut]) {
479480
if (connection.generation <= minGeneration) {
481+
this[kCheckedOut].delete(connection);
480482
connection.onError(new PoolClearedOnNetworkError(this));
481483
this.emit(
482484
ConnectionPool.CONNECTION_CLOSED,
483485
new ConnectionClosedEvent(this, connection, 'stale')
484486
);
485-
486-
return true;
487487
}
488-
return false;
489-
});
490-
491-
if (interruptInUseConnections) {
492-
for (const connection of this[kCheckedOut]) {
493-
if (connection.generation <= minGeneration) {
494-
this[kCheckedOut].delete(connection);
495-
connection.onError(new PoolClearedOnNetworkError(this));
496-
this.emit(
497-
ConnectionPool.CONNECTION_CLOSED,
498-
new ConnectionClosedEvent(this, connection, 'stale')
499-
);
500-
}
501-
}
502-
503-
// TODO(NODE-4784): track pending connections and cancel
504-
// this[kCancellationToken].emit('cancel');
505488
}
489+
490+
// TODO(NODE-4784): track pending connections and cancel
491+
// this[kCancellationToken].emit('cancel');
506492
}
507493

508494
/** Close the pool */

test/integration/connection-monitoring-and-pooling/connection_monitoring_and_pooling.spec.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const INTERRUPT_IN_USE_SKIPPED_TESTS: SkipDescription[] = [
2424
description: 'clear with interruptInUseConnections = true closes pending connections',
2525
skipIfCondition: 'always',
2626
skipReason: 'TODO(NODE-4784): track and kill pending connections'
27+
},
28+
{
29+
description:
30+
'Pool clear SHOULD schedule the next background thread run immediately (interruptInUseConnections: false)',
31+
skipIfCondition: 'always',
32+
skipReason: `NodeJS does not have a background thread responsible for managing connections, and so already checked in connections are not
33+
pruned when in-use connections are interrupted.`
2734
}
2835
];
2936

0 commit comments

Comments
 (0)