-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix MongoClient leak in auto-encryption #1142
Conversation
When AutoEncryptionSettings#keyVaultMongoClientSettings is non-null and AutoEncryptionSettings#isBypassAutoEncryption is false, the second internal MongoClient is now closed when the containing MongoClient is closed. The bug is fixed in both the synchronous and reactive streams drivers. JAVA-4993
@@ -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; |
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
- both be null
- one null and the other non-null
- both be non-null and reference different instances
- both be non-null and reference the same instance
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 comment
The 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 KeyManagementService
uses TlsChannelStreamFactoryFactory
(and needs to be closed), while its sync counterpart does not. Do you happen to know anything about it?
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.
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 AsynchrounousSocketChannel
)
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.
Thanks!
When AutoEncryptionSettings#keyVaultMongoClientSettings is non-null and AutoEncryptionSettings#isBypassAutoEncryption is false, the second internal MongoClient is now closed when the containing MongoClient is closed.
The bug is fixed in both the synchronous and reactive streams drivers.
JAVA-4993