Repository navigation
fix: set a 2 second API call attempt timeout on clients the cache builds - #201
Draft
SushaanthSrinivasan wants to merge 1 commit into
Draft
SushaanthSrinivasan wants to merge 1 commit into
SushaanthSrinivasan wants to merge 1 commit into
Conversation
The SDK sets no attempt timeout by default, so an endpoint that accepts the connection and never answers could block getSecretString for about 2 minutes across retries. Clients the cache builds now get a 2 second apiCallAttemptTimeout unless their builder sets one, and share one daemon timer thread. A built client passed in is used unchanged.
Draft
7 of 8 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v2 #201 +/- ##
============================================
+ Coverage 91.83% 94.59% +2.75%
- Complexity 97 103 +6
============================================
Files 6 6
Lines 245 259 +14
Branches 26 28 +2
============================================
+ Hits 225 245 +20
+ Misses 18 12 -6
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Why is this change being made?
new SecretCache(), with aSecretsManagerClientBuilderpassed in, or with aSecretCacheConfigurationthat has no client. The only limit on an attempt is the HTTP client's socket timeout, which is 30 seconds for the default Apache client. If a Secrets Manager endpoint accepts the connection and then stops responding, each attempt waits 30 seconds, and with the SDK's default retriesgetSecretStringcan block the caller for about 2 minutes.DescribeSecretandGetSecretValuenormally complete in well under 2 seconds. So a 2-second limit catches a connection that has stopped responding without cutting off normal calls. A timed out attempt is retried like any other network error, so one bad connection costs about 2 seconds rather than failing the call.What is changing?
SecretCacheConfiguration.DEFAULT_API_CALL_ATTEMPT_TIMEOUT, set to 2 seconds.apiCallAttemptTimeoutto that value, unless the builder passed in already sets its own attempt timeout. This coversnew SecretCache(),new SecretCache(SecretsManagerClientBuilder), andnew SecretCache(SecretCacheConfiguration)with no client, including the Post-Quantum TLS client. A builtSecretsManagerClientpassed in is used unchanged.close()is unchanged: it clears the cache and doesn't close the client.Behavior changes:
SecretsManagerClientBuilderpassed in, as the user agent already is, so other clients built from that builder later get them too.apiCallAttemptTimeout, or pass in a built client. Setting onlyapiCallTimeoutor HTTP client timeouts on the builder doesn't replace the 2-second default.There are no API changes beyond the new constant.
Related Links
Testing
How was this tested?
New tests in
SecretCacheTest:testDefaultApiCallAttemptTimeout: the constant is 2 seconds.testBuilderClientTimesOutOnHungEndpoint: points a builder passed in at a local socket that accepts the connection but never responds. With retries off, the call fails withApiCallAttemptTimeoutExceptionafter 2 to 5 seconds.testBuilderClientRetriesTimedOutAttempt: with 2 attempts, the same call takes 4 to 8 seconds, so the timed out attempt was retried.testBuilderKeepsOwnAttemptTimeout: a builder that sets 200 ms keeps it.testDefaultClientTimesOutOnHungEndpoint: aSecretCacheConfigurationwith no client, configured only through system properties, also times out after 2 to 5 seconds.testCachesShareOneTimeoutExecutor: six caches start no SDK timer threads (sdk-ScheduledExecutor), and exactly one cache timer thread exists. It's a daemon and uses the library's class loader.testCacheStillWorksAfterClose:close()doesn't close the client, and the cache still works afterwards.The hung-endpoint tests use static dummy credentials and a local endpoint, so they need no AWS account.
Each new test fails without the change.
mvn packagepasses locally with JDK 21 (Corretto), with 0 SpotBugs issues and 0 Checkstyle violations.When testing locally, provide testing artifact(s):
Reviewee Checklist
Update the checklist after submitting the PR
If not, why:
If not, why:
If not, why:
If not, why: Codecov runs in CI on this PR.
If not, why:
If not, why:
If not, why:
If not, why:
Reviewer Checklist
All reviewers please ensure the following are true before reviewing:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.