Skip to content

Add a client-side operation timeout for automatic and explicit field Encryption/Decryption. #1308

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

Merged
merged 11 commits into from
Feb 22, 2024

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin commented Feb 8, 2024

This PR introduces support for the timeoutMS option in both automatic and explicit client-side encryption/decryption within the driver.

Automatic encryption/decryption now uses the timeoutMS value for operational timeouts in listCollections, find commands, and HTTP requests to KMS servers.

For explicit encryption/decryption, the timeoutMS option has been added in ClientEncryptionSettings, offering precise control over timeouts on the ClientEncryption object.

Important Notes:

  • The handling of the maxTimeMS field for mongocryptd commands, as specified, will not be included in this PR due to current design limitations. The removal of maxTimeMS in these scenarios, to maintain command integrity post-libmongocrypt processing, is scheduled for implementation in JAVA-5322, post a necessary refactoring.

  • Similarly, spec requirement to ensure maxTimeMS is not sent to cryptd servers will be addressed in JAVA-5322, following the aforementioned refactoring.

JAVA-4055

@vbabanin vbabanin marked this pull request as ready for review February 8, 2024 15:25
@@ -110,7 +110,7 @@
"listCollections"
],
"blockConnection": true,
"blockTimeMS": 60
Copy link
Member Author

Choose a reason for hiding this comment

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

The timeouts are increased to accommodate for the additional time required for SSL handshake when authentication is enabled. This adjustment ensures that the timeout does not expire before the expected steps in our tests are completed.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment in below the file description - just so its easier to understand if / when these files get updated in the future

One example is change-streams.json:
"comment": "Manually updated some of the timeoutMS and blockTimeMS to remove race conditions",

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion, thank you! I've added the comment.

Fix test.

JAVA-4055
@vbabanin vbabanin requested a review from rozza February 8, 2024 22:56
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

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

Looks really good - a couple of nits then LGTM.

// Tests expect maxTimeMS to be int32, but Java API requires maxTime to be a long. This massage seems preferable to casting
if (command.containsKey("maxTimeMS")) {
command.put("maxTimeMS", new BsonInt32(command.getNumber("maxTimeMS").intValue()));
if (actualCommand.containsKey("maxTimeMS") && !isExpectedMaxTimeMsLong(expectedCommand)) {
Copy link
Member

Choose a reason for hiding this comment

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

Ugh - this is fun!!

@@ -110,7 +110,7 @@
"listCollections"
],
"blockConnection": true,
"blockTimeMS": 60
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment in below the file description - just so its easier to understand if / when these files get updated in the future

One example is change-streams.json:
"comment": "Manually updated some of the timeoutMS and blockTimeMS to remove race conditions",


public static Mono<MongoDatabase> databaseWithTimeoutDeferred(final MongoDatabase database,
@Nullable final Timeout timeout) {
return Mono.defer(() -> databaseWithTimeoutMono(database, DEFAULT_TIMEOUT_MESSAGE, timeout));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Chain to use databaseWithTimeoutDeferred below.

@vbabanin vbabanin requested a review from jyemin February 12, 2024 16:55
@vbabanin vbabanin changed the title Add a client-side operation timeout for field-level encryption. Add a client-side operation timeout for automatic and explicit field Encryption/Decryption. Feb 12, 2024
Chain methods.

JAVA-4055
# Conflicts:
#	driver-reactive-streams/src/test/functional/com/mongodb/reactivestreams/client/ClientSideOperationTimeoutProseTest.java
JAVA-4045
@jyemin jyemin removed their request for review February 21, 2024 18:18
@jyemin
Copy link
Collaborator

jyemin commented Feb 21, 2024

@vbabanin not sure if you were waiting for me on this, but I removed myself as a reviewer.

@vbabanin vbabanin merged commit 5966e95 into mongodb:CSOT Feb 22, 2024
@vbabanin vbabanin deleted the JAVA--4045 branch February 22, 2024 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants