Skip to content
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

Merged
merged 1 commit into from
Jun 12, 2023
Merged

Conversation

jyemin
Copy link
Contributor

@jyemin jyemin commented Jun 9, 2023

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

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
@jyemin jyemin self-assigned this Jun 9, 2023
@@ -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;
Copy link
Contributor Author

@jyemin jyemin Jun 9, 2023

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

@jyemin jyemin requested a review from stIncMale June 9, 2023 13:41
KeyManagementService ignored3 = this.keyManagementService
MongoClient ignored2 = this.collectionInfoRetrieverClient;
MongoClient ignored3 = this.keyVaultClient;
KeyManagementService ignored4 = this.keyManagementService
Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jyemin jyemin merged commit 6332c14 into mongodb:master Jun 12, 2023
54 checks passed
@jyemin jyemin deleted the j4993 branch June 12, 2023 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants