@@ -18,6 +18,7 @@ import {
1818 ConnectionCheckedInEvent ,
1919 ConnectionPoolClearedEvent
2020} from './connection_pool_events' ;
21+ import type { ObjectId } from '../bson' ;
2122
2223const kLogger = Symbol ( 'logger' ) ;
2324const kConnections = Symbol ( 'connections' ) ;
@@ -270,6 +271,17 @@ export class ConnectionPool extends EventEmitter {
270271 this . emit ( 'connectionPoolCleared' , new ConnectionPoolClearedEvent ( this ) ) ;
271272 }
272273
274+ /**
275+ * Close all connections in the pool for the provided serviceId.
276+ */
277+ closeConnections ( serviceId : ObjectId ) : void {
278+ // cancel in flight matching connections.
279+ this [ kCancellationToken ] . emit ( 'cancel' , serviceId ) ;
280+
281+ // destroy each matching connection
282+ // this.destroyConnections('serverError', {}, serviceId, callback);
283+ }
284+
273285 /** Close the pool */
274286 close ( callback : Callback < void > ) : void ;
275287 close ( options : CloseOptions , callback : Callback < void > ) : void ;
@@ -314,19 +326,25 @@ export class ConnectionPool extends EventEmitter {
314326
315327 // mark the pool as closed immediately
316328 this . closed = true ;
317-
318329 eachAsync < Connection > (
319330 this [ kConnections ] . toArray ( ) ,
320331 ( conn , cb ) => {
332+ // Destroy the connection in the case of closing the entire pool
333+ // or if the connection matches the server id.
334+ //if (!serviceId || serviceId === conn.serviceId) {
321335 this . emit (
322336 ConnectionPool . CONNECTION_CLOSED ,
323337 new ConnectionClosedEvent ( this , conn , 'poolClosed' )
324338 ) ;
325339 conn . destroy ( options , cb ) ;
340+ //}
326341 } ,
327342 err => {
343+ // Dont close the entire pool for error on single server.
344+ //if (!serviceId) {
328345 this [ kConnections ] . clear ( ) ;
329346 this . emit ( ConnectionPool . CONNECTION_POOL_CLOSED , new ConnectionPoolClosedEvent ( this ) ) ;
347+ //}
330348 callback ( err ) ;
331349 }
332350 ) ;
@@ -382,6 +400,7 @@ function connectionIsIdle(pool: ConnectionPool, connection: Connection) {
382400 return ! ! ( pool . options . maxIdleTimeMS && connection . idleTime > pool . options . maxIdleTimeMS ) ;
383401}
384402
403+ // TODO: Durran: In LB mode set the server id on the connection.
385404function createConnection ( pool : ConnectionPool , callback ?: Callback < Connection > ) {
386405 const connectOptions : ConnectionOptions = {
387406 ...pool . options ,
0 commit comments