-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Retry KMS requests on transient errors #1953
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
base: main
Are you sure you want to change the base?
Changes from all commits
77f99cc
41b3cdd
e5f639e
634f46f
1bf23b7
1dc2c06
6e6a880
f1fd43c
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Don't trace since the URI contains a password that shouldn't show up in the logs | ||
| set -o errexit # Exit the script with error if any of the commands fail | ||
|
|
||
| # Supported/used environment variables: | ||
| # MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info) | ||
|
|
||
| ############################################ | ||
| # Main Program # | ||
| ############################################ | ||
| RELATIVE_DIR_PATH="$(dirname "${BASH_SOURCE:-$0}")" | ||
| . "${RELATIVE_DIR_PATH}/setup-env.bash" | ||
| echo "Running KMS Retry tests" | ||
|
|
||
| cp ${JAVA_HOME}/lib/security/cacerts mongo-truststore | ||
| ${JAVA_HOME}/bin/keytool -importcert -trustcacerts -file ${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem -keystore mongo-truststore -storepass changeit -storetype JKS -noprompt | ||
|
|
||
| export GRADLE_EXTRA_VARS="-Pssl.enabled=true -Pssl.trustStoreType=jks -Pssl.trustStore=`pwd`/mongo-truststore -Pssl.trustStorePassword=changeit" | ||
|
|
||
| ./gradlew -version | ||
|
|
||
| # Disable errexit so both suites run and their exit codes can be captured below. | ||
| set +o errexit | ||
|
|
||
| ./gradlew --stacktrace --info ${GRADLE_EXTRA_VARS} -Dorg.mongodb.test.uri=${MONGODB_URI} \ | ||
| -Dorg.mongodb.test.kms.retry.ca.path="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem" \ | ||
| driver-sync:cleanTest driver-sync:test --tests ClientSideEncryptionKmsRetryProseTest | ||
| first=$? | ||
| echo $first | ||
|
|
||
| ./gradlew --stacktrace --info ${GRADLE_EXTRA_VARS} -Dorg.mongodb.test.uri=${MONGODB_URI} \ | ||
| -Dorg.mongodb.test.kms.retry.ca.path="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem" \ | ||
| driver-reactive-streams:cleanTest driver-reactive-streams:test --tests ClientSideEncryptionKmsRetryProseTest | ||
|
rozza marked this conversation as resolved.
|
||
| second=$? | ||
| echo $second | ||
|
|
||
| if [ $first -ne 0 ]; then | ||
| exit $first | ||
| elif [ $second -ne 0 ]; then | ||
| exit $second | ||
| else | ||
| exit 0 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,10 +236,13 @@ public long read(ByteBufferSet dest) throws IOException { | |
| case NOT_HANDSHAKING: | ||
| case FINISHED: | ||
| UnwrapResult res = readAndUnwrap(Optional.of(dest)); | ||
| bytesToReturn = res.bytesProduced; | ||
| if (res.wasClosed) { | ||
| return -1; | ||
| // JAVA-5391: return any bytes produced alongside close_notify; the next read | ||
| // sees shutdownReceived and returns -1. Fixed in upstream marianobarrios/tls-channel; | ||
| // this is the minimal patch until the vendored snapshot is refreshed. | ||
| return bytesToReturn > 0 ? bytesToReturn : -1; | ||
|
Comment on lines
+239
to
+244
Member
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. Could you please
I think, given that this change is in a vendored code, we should do it in a separate PR, to avoid complicating the future work of updating the vendored code.
Member
Author
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. Yes it was causing the tests to fail (I can't recall which one) but it was not returning bytes that needed to be read. Most likely the mock kms server.
Member
Author
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. Ah yes it was:
If causes: MongoClientException: Exception in encryption library: Allocation size must be greater than zero. It doesn't happen on sync because it uses SSLSocket/InputStream, which correctly delivers data before signalling EOF on close_notify. It isn't triggered by gcp or azure because the failpoint fires on the OAuth token request. So the actual key operation uses another connection and succeeds. As AWS doesn't use a token, and fails with data unconsumed on the wire. According to Claude:
TLSChannelImpl fixed this behaviour in 0.5.0 |
||
| } | ||
| bytesToReturn = res.bytesProduced; | ||
| handshakeStatus = res.lastHandshakeStatus; | ||
| break; | ||
| case NEED_TASK: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2008-present MongoDB, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.mongodb.reactivestreams.client; | ||
|
|
||
| import com.mongodb.ClientEncryptionSettings; | ||
| import com.mongodb.client.AbstractClientSideEncryptionKmsRetryProseTest; | ||
| import com.mongodb.client.vault.ClientEncryption; | ||
| import com.mongodb.reactivestreams.client.syncadapter.SyncClientEncryption; | ||
| import com.mongodb.reactivestreams.client.vault.ClientEncryptions; | ||
|
|
||
| public class ClientSideEncryptionKmsRetryProseTest extends AbstractClientSideEncryptionKmsRetryProseTest { | ||
| @Override | ||
| public ClientEncryption getClientEncryption(final ClientEncryptionSettings settings) { | ||
| return new SyncClientEncryption(ClientEncryptions.create(settings)); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.