Skip to content

Commit ff8e814

Browse files
committed
test: deadlock if in-use connections not closed
1 parent f8bfe7e commit ff8e814

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test/integration/node-specific/mongo_client.test.ts

+51-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import {
1212
Db,
1313
getTopology,
1414
MongoClient,
15+
MongoClientClosedError,
1516
MongoNotConnectedError,
1617
MongoServerSelectionError,
1718
ReadPreference,
1819
ServerDescription,
1920
Topology
2021
} from '../../mongodb';
21-
import { runLater } from '../../tools/utils';
22+
import { clearFailPoint, configureFailPoint, runLater } from '../../tools/utils';
2223
import { setupDatabase } from '../shared';
2324

2425
describe('class MongoClient', function () {
@@ -1064,6 +1065,55 @@ describe('class MongoClient', function () {
10641065
expect(client.s.activeCursors).to.have.lengthOf(1);
10651066
});
10661067
});
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+
);
10671117
});
10681118

10691119
context('when connecting', function () {

0 commit comments

Comments
 (0)