Skip to content

Commit

Permalink
fix(autoEncryption): tear down mongocryptd client when main client cl…
Browse files Browse the repository at this point in the history
…oses

Fixes NODE-2051
  • Loading branch information
daprahamian committed Aug 13, 2019
1 parent d3670c2 commit fe2f57e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/operations/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/operations/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit fe2f57e

Please sign in to comment.