@@ -104,6 +104,7 @@ export interface WaitQueueMember {
104
104
reject : ( err : AnyError ) => void ;
105
105
timeout : Timeout ;
106
106
[ kCancelled ] ?: boolean ;
107
+ checkoutTime : number ;
107
108
}
108
109
109
110
/** @internal */
@@ -162,7 +163,6 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
162
163
[ kWaitQueue ] : List < WaitQueueMember > ;
163
164
[ kMetrics ] : ConnectionPoolMetrics ;
164
165
[ kProcessingWaitQueue ] : boolean ;
165
- checkOutTime : undefined | number ;
166
166
167
167
/**
168
168
* Emitted when the connection pool is created.
@@ -356,7 +356,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
356
356
* explicitly destroyed by the new owner.
357
357
*/
358
358
async checkOut ( ) : Promise < Connection > {
359
- this . checkOutTime = Date . now ( ) ;
359
+ const checkoutTime = Date . now ( ) ;
360
360
this . emitAndLog (
361
361
ConnectionPool . CONNECTION_CHECK_OUT_STARTED ,
362
362
new ConnectionCheckOutStartedEvent ( this )
@@ -371,7 +371,8 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
371
371
const waitQueueMember : WaitQueueMember = {
372
372
resolve,
373
373
reject,
374
- timeout
374
+ timeout,
375
+ checkoutTime
375
376
} ;
376
377
377
378
this [ kWaitQueue ] . push ( waitQueueMember ) ;
@@ -387,7 +388,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
387
388
388
389
this . emitAndLog (
389
390
ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
390
- new ConnectionCheckOutFailedEvent ( this , 'timeout' )
391
+ new ConnectionCheckOutFailedEvent ( this , 'timeout' , waitQueueMember . checkoutTime )
391
392
) ;
392
393
const timeoutError = new WaitQueueTimeoutError (
393
394
this . loadBalanced
@@ -762,7 +763,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
762
763
const error = this . closed ? new PoolClosedError ( this ) : new PoolClearedError ( this ) ;
763
764
this . emitAndLog (
764
765
ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
765
- new ConnectionCheckOutFailedEvent ( this , reason , error )
766
+ new ConnectionCheckOutFailedEvent ( this , reason , waitQueueMember . checkoutTime , error )
766
767
) ;
767
768
waitQueueMember . timeout . clear ( ) ;
768
769
this [ kWaitQueue ] . shift ( ) ;
@@ -783,7 +784,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
783
784
this [ kCheckedOut ] . add ( connection ) ;
784
785
this . emitAndLog (
785
786
ConnectionPool . CONNECTION_CHECKED_OUT ,
786
- new ConnectionCheckedOutEvent ( this , connection )
787
+ new ConnectionCheckedOutEvent ( this , connection , waitQueueMember . checkoutTime )
787
788
) ;
788
789
waitQueueMember . timeout . clear ( ) ;
789
790
@@ -812,14 +813,19 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
812
813
this . emitAndLog (
813
814
ConnectionPool . CONNECTION_CHECK_OUT_FAILED ,
814
815
// TODO(NODE-5192): Remove this cast
815
- new ConnectionCheckOutFailedEvent ( this , 'connectionError' , err as MongoError )
816
+ new ConnectionCheckOutFailedEvent (
817
+ this ,
818
+ 'connectionError' ,
819
+ waitQueueMember . checkoutTime ,
820
+ err as MongoError
821
+ )
816
822
) ;
817
823
waitQueueMember . reject ( err ) ;
818
824
} else if ( connection ) {
819
825
this [ kCheckedOut ] . add ( connection ) ;
820
826
this . emitAndLog (
821
827
ConnectionPool . CONNECTION_CHECKED_OUT ,
822
- new ConnectionCheckedOutEvent ( this , connection )
828
+ new ConnectionCheckedOutEvent ( this , connection , waitQueueMember . checkoutTime )
823
829
) ;
824
830
waitQueueMember . resolve ( connection ) ;
825
831
}
0 commit comments