-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix MongoClient leak in auto-encryption #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,9 @@ public class Crypt implements Closeable { | |
private final KeyManagementService keyManagementService; | ||
private final boolean bypassAutoEncryption; | ||
@Nullable | ||
private final MongoClient internalClient; | ||
private final MongoClient collectionInfoRetrieverClient; | ||
@Nullable | ||
private final MongoClient keyVaultClient; | ||
|
||
/** | ||
* Create an instance to use for explicit encryption and decryption, and data key creation. | ||
|
@@ -81,7 +83,7 @@ public class Crypt implements Closeable { | |
final Map<String, Map<String, Object>> kmsProviders, | ||
final Map<String, Supplier<Map<String, Object>>> kmsProviderPropertySuppliers) { | ||
this(mongoCrypt, keyRetriever, keyManagementService, kmsProviders, kmsProviderPropertySuppliers, | ||
false, null, null, null); | ||
false, null, null, null, null); | ||
} | ||
|
||
/** | ||
|
@@ -95,7 +97,8 @@ public class Crypt implements Closeable { | |
* @param bypassAutoEncryption the bypass auto encryption flag | ||
* @param collectionInfoRetriever the collection info retriever | ||
* @param commandMarker the command marker | ||
* @param internalClient the internal mongo client | ||
* @param collectionInfoRetrieverClient the collection info retriever mongo client | ||
* @param keyVaultClient the key vault mongo client | ||
*/ | ||
Crypt(final MongoCrypt mongoCrypt, | ||
final KeyRetriever keyRetriever, | ||
|
@@ -105,7 +108,8 @@ public class Crypt implements Closeable { | |
final boolean bypassAutoEncryption, | ||
@Nullable final CollectionInfoRetriever collectionInfoRetriever, | ||
@Nullable final CommandMarker commandMarker, | ||
@Nullable final MongoClient internalClient) { | ||
@Nullable final MongoClient collectionInfoRetrieverClient, | ||
@Nullable final MongoClient keyVaultClient) { | ||
this.mongoCrypt = mongoCrypt; | ||
this.keyRetriever = keyRetriever; | ||
this.keyManagementService = keyManagementService; | ||
|
@@ -114,7 +118,8 @@ public class Crypt implements Closeable { | |
this.bypassAutoEncryption = bypassAutoEncryption; | ||
this.collectionInfoRetriever = collectionInfoRetriever; | ||
this.commandMarker = commandMarker; | ||
this.internalClient = internalClient; | ||
this.collectionInfoRetrieverClient = collectionInfoRetrieverClient; | ||
this.keyVaultClient = keyVaultClient; | ||
} | ||
|
||
/** | ||
|
@@ -227,8 +232,9 @@ public void close() { | |
//noinspection EmptyTryBlock | ||
try (MongoCrypt ignored = this.mongoCrypt; | ||
CommandMarker ignored1 = this.commandMarker; | ||
MongoClient ignored2 = this.internalClient; | ||
KeyManagementService ignored3 = this.keyManagementService | ||
MongoClient ignored2 = this.collectionInfoRetrieverClient; | ||
MongoClient ignored3 = this.keyVaultClient; | ||
KeyManagementService ignored4 = this.keyManagementService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related to the PR changes, but it's not obvious why the async There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's because with async I/O you need a thread pool to handle the I/O completion, and for the library that we're using for async TLS there is no "system" (i.e. global) thread pool that is used (unlike with the JDK's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
) { | ||
// just using try-with-resources to ensure they all get closed, even in the case of exceptions | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on configuration, these two MongoClient instances may either