@@ -12,13 +12,14 @@ import {
12
12
Db ,
13
13
getTopology ,
14
14
MongoClient ,
15
+ MongoClientClosedError ,
15
16
MongoNotConnectedError ,
16
17
MongoServerSelectionError ,
17
18
ReadPreference ,
18
19
ServerDescription ,
19
20
Topology
20
21
} from '../../mongodb' ;
21
- import { runLater } from '../../tools/utils' ;
22
+ import { clearFailPoint , configureFailPoint , runLater } from '../../tools/utils' ;
22
23
import { setupDatabase } from '../shared' ;
23
24
24
25
describe ( 'class MongoClient' , function ( ) {
@@ -1064,6 +1065,55 @@ describe('class MongoClient', function () {
1064
1065
expect ( client . s . activeCursors ) . to . have . lengthOf ( 1 ) ;
1065
1066
} ) ;
1066
1067
} ) ;
1068
+
1069
+ describe (
1070
+ 'maxPoolSize is not fully used when running clean up operations' ,
1071
+ { requires : { mongodb : '>=4.4' , topology : 'single' } } ,
1072
+ function ( ) {
1073
+ let client ;
1074
+
1075
+ beforeEach ( async function ( ) {
1076
+ await configureFailPoint ( this . configuration , {
1077
+ configureFailPoint : 'failCommand' ,
1078
+ mode : 'alwaysOn' ,
1079
+ data : {
1080
+ failCommands : [ 'insert' ] ,
1081
+ blockConnection : true ,
1082
+ blockTimeMS : 500
1083
+ }
1084
+ } ) ;
1085
+
1086
+ client = this . configuration . newClient ( { } , { maxPoolSize : 1 , monitorCommands : true } ) ;
1087
+ } ) ;
1088
+
1089
+ afterEach ( async function ( ) {
1090
+ await clearFailPoint ( this . configuration ) ;
1091
+ await client . close ( ) ;
1092
+ } ) ;
1093
+
1094
+ it (
1095
+ 'closes in-use connections before running clean up operations avoiding a deadlock' ,
1096
+ { requires : { mongodb : '>=4.4' , topology : 'single' } } ,
1097
+ async ( ) => {
1098
+ const inserted = client
1099
+ . db ( 't' )
1100
+ . collection ( 't' )
1101
+ . insertOne ( { a : 1 } )
1102
+ . catch ( error => error ) ;
1103
+
1104
+ await once ( client , 'commandStarted' ) ;
1105
+
1106
+ const start = performance . now ( ) ;
1107
+ await client . close ( ) ;
1108
+ const error = await inserted ;
1109
+ const end = performance . now ( ) ;
1110
+
1111
+ expect ( end - start ) . to . be . lessThan ( 100 ) ;
1112
+ expect ( error ) . to . be . instanceOf ( MongoClientClosedError ) ;
1113
+ }
1114
+ ) ;
1115
+ }
1116
+ ) ;
1067
1117
} ) ;
1068
1118
1069
1119
context ( 'when connecting' , function ( ) {
0 commit comments