File tree Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Original file line number Diff line number Diff line change @@ -303,7 +303,29 @@ export class Server extends TypedEventEmitter<ServerEvents> {
303
303
}
304
304
}
305
305
306
- const cmd = operation . buildCommand ( conn , session ) ;
306
+ const cleanup = ( ) => {
307
+ this . decrementOperationCount ( ) ;
308
+ if ( session ?. pinnedConnection !== conn ) {
309
+ if ( reauthPromise != null ) {
310
+ // The reauth promise only exists if it hasn't thrown.
311
+ const checkBackIn = ( ) => {
312
+ this . pool . checkIn ( conn ) ;
313
+ } ;
314
+ void reauthPromise . then ( checkBackIn , checkBackIn ) ;
315
+ } else {
316
+ this . pool . checkIn ( conn ) ;
317
+ }
318
+ }
319
+ } ;
320
+
321
+ let cmd ;
322
+ try {
323
+ cmd = operation . buildCommand ( conn , session ) ;
324
+ } catch ( e ) {
325
+ cleanup ( ) ;
326
+ throw e ;
327
+ }
328
+
307
329
const options = operation . buildOptions ( timeoutContext ) ;
308
330
const ns = operation . ns ;
309
331
@@ -360,18 +382,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
360
382
throw operationError ;
361
383
}
362
384
} finally {
363
- this . decrementOperationCount ( ) ;
364
- if ( session ?. pinnedConnection !== conn ) {
365
- if ( reauthPromise != null ) {
366
- // The reauth promise only exists if it hasn't thrown.
367
- const checkBackIn = ( ) => {
368
- this . pool . checkIn ( conn ) ;
369
- } ;
370
- void reauthPromise . then ( checkBackIn , checkBackIn ) ;
371
- } else {
372
- this . pool . checkIn ( conn ) ;
373
- }
374
- }
385
+ cleanup ( ) ;
375
386
}
376
387
}
377
388
You can’t perform that action at this time.
0 commit comments