Skip to content

Commit

Permalink
refactor: make Pool.clear take options object
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Oct 27, 2022
1 parent c438bcf commit 90181b1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cmap/connection_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
* Pool reset is handled by incrementing the pool's generation count. Any existing connection of a
* previous generation will eventually be pruned during subsequent checkouts.
*/
clear(serviceId?: ObjectId): void {
clear(options: { serviceId?: ObjectId } = {}): void {
const { serviceId } = options;
if (this.closed) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sdam/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@ export class Server extends TypedEventEmitter<ServerEvents> {
error.addErrorLabel(MongoErrorLabel.ResetPool);
markServerUnknown(this, error);
} else if (connection) {
this.s.pool.clear(connection.serviceId);
this.s.pool.clear({ serviceId: connection.serviceId });
}
} else {
if (isSDAMUnrecoverableError(error)) {
if (shouldHandleStateChangeError(this, error)) {
const shouldClearPool = maxWireVersion(this) <= 7 || isNodeShuttingDownError(error);
if (this.loadBalanced && connection && shouldClearPool) {
this.s.pool.clear(connection.serviceId);
this.s.pool.clear({ serviceId: connection.serviceId });
}

if (!this.loadBalanced) {
Expand Down
2 changes: 1 addition & 1 deletion src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export function maybeClearPinnedConnection(
);

if (options?.forceClear) {
loadBalancer.s.pool.clear(conn.serviceId);
loadBalancer.s.pool.clear({ serviceId: conn.serviceId });
}
}

Expand Down

0 comments on commit 90181b1

Please sign in to comment.