Skip to content

Commit fe2f57e

Browse files
committed
fix(autoEncryption): tear down mongocryptd client when main client closes
Fixes NODE-2051
1 parent d3670c2 commit fe2f57e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/operations/close.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ class CloseOperation extends OperationBase {
2323
client.removeAllListeners('close');
2424
callback(err, null);
2525
};
26+
const mongocryptdClientClose = err => {
27+
const mongocryptdClient = client.s.mongocryptdClient;
28+
if (!mongocryptdClient) {
29+
completeClose(err);
30+
return;
31+
}
32+
33+
mongocryptdClient.close(force, err2 => completeClose(err || err2));
34+
};
2635

2736
if (client.topology == null) {
28-
completeClose();
37+
mongocryptdClientClose();
2938
return;
3039
}
3140

32-
client.topology.close(force, completeClose);
41+
client.topology.close(force, mongocryptdClientClose);
3342
}
3443
}
3544

lib/operations/connect.js

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ function createTopology(mongoClient, topologyType, options, callback) {
497497
useNewUrlParser: true,
498498
useUnifiedTopology: true
499499
});
500+
mongoClient.s.mongocryptdClient = mongocryptdClient;
500501
mongocryptdClient.connect(err => {
501502
if (err) return callback(err, null);
502503

0 commit comments

Comments
 (0)