-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Summary
Customers can use the parameters utility from multi-threaded context. For instance, when using the Batch utility using parallel processing.
This can cause a race condition in the underlying data structure that was created to support the fluent API (https://docs.aws.amazon.com/powertools/java/latest/utilities/parameters/#fluent-api).
Example:
Thread 1: provider.withMaxAge(60, SECONDS).get("key1")
Thread 2: provider.withMaxAge(10, SECONDS).get("key2")
.withMaxAge and also .withTransformation internally set a instance variable on the cache manager (or transformation manager). This is problematic because in the example above thread 2 could set the max age before thread 1 has actually cached "key1" with the correct age.
We should fix such race-conditions and mark the BaseProvider as @ThreadSafe.
Why is this needed?
Thread-safety is a general expectation that is also fulfilled by AWS SDKs. Hence, we should keep the same quality bar for Powertools utilities.
Which area does this relate to?
Parameters
Solution
When implementing this solution we need to make sure that the cached values are still accessible across threads because this is the whole purpose of the cache.
Acknowledgment
- This request meets Powertools for AWS Lambda (Java) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, TypeScript
Metadata
Metadata
Assignees
Labels
Type
Projects
Status