Skip to content

Commit 7d97dfa

Browse files
committed
remove extraneous async logic
1 parent 15d1b7a commit 7d97dfa

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

src/cmap/connection_pool.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
500500
}
501501

502502
/** Close the pool */
503-
close(_options?: CloseOptions): void {
504-
let options = _options as CloseOptions;
505-
if (typeof options === 'function') {
506-
options = {};
507-
}
508-
509-
options = Object.assign({ force: false }, options);
503+
close(): void {
510504
if (this.closed) {
511505
return;
512506
}
@@ -583,7 +577,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
583577
new ConnectionClosedEvent(this, connection, reason)
584578
);
585579
// destroy the connection
586-
process.nextTick(() => connection.destroy());
580+
connection.destroy();
587581
}
588582

589583
private connectionIsStale(connection: Connection) {

src/sdam/server.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Document } from '../bson';
22
import { type AutoEncrypter } from '../client-side-encryption/auto_encrypter';
3-
import { type CommandOptions, Connection, type DestroyOptions } from '../cmap/connection';
3+
import { type CommandOptions, Connection } from '../cmap/connection';
44
import {
55
ConnectionPool,
66
type ConnectionPoolEvents,
@@ -235,9 +235,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
235235
}
236236

237237
/** Destroy the server connection */
238-
destroy(options?: DestroyOptions): void {
239-
options = Object.assign({}, { force: false }, options);
240-
238+
destroy(): void {
241239
if (this.s.state === STATE_CLOSED) {
242240
return;
243241
}
@@ -248,7 +246,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
248246
this.monitor?.close();
249247
}
250248

251-
this.pool.close(options);
249+
this.pool.close();
252250
stateTransition(this, STATE_CLOSED);
253251
this.emit('closed');
254252
}

src/sdam/topology.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { promisify } from 'util';
22

33
import type { BSONSerializeOptions, Document } from '../bson';
44
import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
5-
import type { ConnectionEvents, DestroyOptions } from '../cmap/connection';
6-
import type { CloseOptions, ConnectionPoolEvents } from '../cmap/connection_pool';
5+
import type { ConnectionEvents } from '../cmap/connection';
6+
import type { ConnectionPoolEvents } from '../cmap/connection_pool';
77
import type { ClientMetadata } from '../cmap/handshake/client_metadata';
88
import { DEFAULT_OPTIONS, FEATURE_FLAGS } from '../connection_string';
99
import {
@@ -468,7 +468,8 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
468468
selectServerOptions,
469469
(err, server) => {
470470
if (err) {
471-
return this.close({ force: false }, () => exitWithError(err));
471+
this.close();
472+
exitWithError(err);
472473
}
473474

474475
const skipPingOnConnect = this.s.options[Symbol.for('@@mdb.skipPingOnConnect')] === true;
@@ -494,15 +495,13 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
494495
}
495496

496497
/** Close this topology */
497-
close(options?: CloseOptions): void {
498-
options = options ?? { force: false };
499-
498+
close(): void {
500499
if (this.s.state === STATE_CLOSED || this.s.state === STATE_CLOSING) {
501500
return;
502501
}
503502

504503
for (const server of this.s.servers.values()) {
505-
destroyServer(server, this, { force: !!options?.force });
504+
destroyServer(server, this);
506505
}
507506

508507
this.s.servers.clear();
@@ -766,30 +765,20 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
766765
}
767766

768767
/** Destroys a server, and removes all event listeners from the instance */
769-
function destroyServer(
770-
server: Server,
771-
topology: Topology,
772-
options?: DestroyOptions,
773-
callback?: Callback
774-
) {
775-
options = options ?? { force: false };
768+
function destroyServer(server: Server, topology: Topology) {
776769
for (const event of LOCAL_SERVER_EVENTS) {
777770
server.removeAllListeners(event);
778771
}
779772

780-
server.destroy(options, () => {
781-
topology.emitAndLog(
782-
Topology.SERVER_CLOSED,
783-
new ServerClosedEvent(topology.s.id, server.description.address)
784-
);
773+
server.destroy();
774+
topology.emitAndLog(
775+
Topology.SERVER_CLOSED,
776+
new ServerClosedEvent(topology.s.id, server.description.address)
777+
);
785778

786-
for (const event of SERVER_RELAY_EVENTS) {
787-
server.removeAllListeners(event);
788-
}
789-
if (typeof callback === 'function') {
790-
callback();
791-
}
792-
});
779+
for (const event of SERVER_RELAY_EVENTS) {
780+
server.removeAllListeners(event);
781+
}
793782
}
794783

795784
/** Predicts the TopologyType from options */

0 commit comments

Comments
 (0)