Skip to content
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

[Feature] Synchronized version of AwsCrtV4aSigner #5162

Open
2 tasks
noCharger opened this issue Apr 26, 2024 · 0 comments
Open
2 tasks

[Feature] Synchronized version of AwsCrtV4aSigner #5162

noCharger opened this issue Apr 26, 2024 · 0 comments
Labels
feature-request A feature should be added or improved. needs-review This issue or PR needs review from the team.

Comments

@noCharger
Copy link

Describe the feature

The feature request is for an implementation of the AwsCrtV4aSigner that either uses synchronized signing method or employs non-daemon threads during signing operations.

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<HttpRequest> signRequest(HttpRequest request, AwsSigningConfig config) {
        CompletableFuture<HttpRequest> future = new CompletableFuture<HttpRequest>();
        CompletableFuture<AwsSigningResult> 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

AWS Java SDK version used

2.25.23

JDK version used

openjdk version "14.0.2" 2020-07-14

Operating System and version

N/A

@noCharger noCharger added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Apr 26, 2024
@debora-ito debora-ito added needs-review This issue or PR needs review from the team. and removed needs-triage This issue or PR still needs to be triaged. labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. needs-review This issue or PR needs review from the team.
Projects
None yet
Development

No branches or pull requests

2 participants