awslabs / awslabs/aws-crt-java
[Feature] Synchronized version of AwsCrt4aSigningAdapter
- Dominant language
- Java
- Stars
- 76
- Forks
- 46
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the feature
The feature request is for an implementation of the `AwsCrt4aSigningAdapter` that either uses synchronized signing method or employs non-daemon threads during signing operations.
https://github.com/aws/aws-sdk-java-v2/blob/80e1821456aea846fca72ee6d0ffdb8b82a3ea48/core/auth-crt/src/main/java/software/amazon/awssdk/authcrt/signer/internal/AwsCrt4aSigningAdapter.java#L48
### Use Case
The current SigV4a signer is implemented asynchronously using `CompletableFuture`, which defaults to using daemon thread. However, in specific scenarios such as when Spark's `ShutdownHookManager` is active, these daemon threads can be prematurely interrupted, leading to potential issues.
### Proposed Solution
An implementation of the `AwsCrtV4aSigner` that either uses synchronized signing method or employs non-daemon threads during signing operations.
Pseudo code
```
public class AwsSigner {
private static final ThreadFactory nonDaemonThreadFactory = new ThreadFactory() {
private final AtomicInteger threadCount = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setDaemon(false); // Set the thread as non-daemon
t.setName("AwsSignerThread-" + threadCount.getAndIncrement());
return t;
}
};
/**
* Signs an http request according to the supplied signing configuration
* @param request http request to sign
* @param config signing configuration
* @return future which will contain the signed request
*/
static public CompletableFuture signRequest(HttpRequest request, AwsSigningConfig config) {
CompletableFuture future = new CompletableFuture();
CompletableFuture result = AwsSigner.sign(request, config);
result.whenCompleteAsync((res, throwable) -> {
if (throwable != null) {
future.completeExceptionally(throwable);
} else {
future.complete(res.getSignedRequest());
}
}, Executors.newSingleThreadExecutor(nonDaemonThreadFactory));
return future;
}
}
```
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
Contributor guide
Research direction
Start with core/auth-crt/src/main/java/software/amazon/awssdk/authcrt/signer/internal/AwsCrt4aSigningAdapter.java at the referenced signing path, then inspect how AwsCrtV4aSigner completes its CompletableFuture. Determine whether synchronized signing or non-daemon execution fits the existing design, and define completion around signing surviving the described shutdown-hook scenario without breaking request results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100