diff --git a/lib/operations/close.js b/lib/operations/close.js index e9a12cf0e0..bbc1c3a04d 100644 --- a/lib/operations/close.js +++ b/lib/operations/close.js @@ -23,13 +23,22 @@ class CloseOperation extends OperationBase { client.removeAllListeners('close'); callback(err, null); }; + const mongocryptdClientClose = err => { + const mongocryptdClient = client.s.mongocryptdClient; + if (!mongocryptdClient) { + completeClose(err); + return; + } + + mongocryptdClient.close(force, err2 => completeClose(err || err2)); + }; if (client.topology == null) { - completeClose(); + mongocryptdClientClose(); return; } - client.topology.close(force, completeClose); + client.topology.close(force, mongocryptdClientClose); } } diff --git a/lib/operations/connect.js b/lib/operations/connect.js index 54b5c8a1cf..57bd299fe8 100644 --- a/lib/operations/connect.js +++ b/lib/operations/connect.js @@ -497,6 +497,7 @@ function createTopology(mongoClient, topologyType, options, callback) { useNewUrlParser: true, useUnifiedTopology: true }); + mongoClient.s.mongocryptdClient = mongocryptdClient; mongocryptdClient.connect(err => { if (err) return callback(err, null);