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

Stuck on java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit) when using java.util.concurrent.Executors#newVirtualThreadPerTaskExecutor #5248

Closed
ashr123 opened this issue May 28, 2024 · 2 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@ashr123
Copy link

ashr123 commented May 28, 2024

Describe the bug

When using java.util.concurrent.Executors#newVirtualThreadPerTaskExecutor & java.util.concurrent.ExecutorService#invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>>, long, java.util.concurrent.TimeUnit) & inside the Callable I call software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable#getItem(software.amazon.awssdk.enhanced.dynamodb.Key), the code doesn't return from the getItem method, in addition, the Future#get doesn't return either from cancelation or timeout

Expected Behavior

Return normally or return exceptionally with CancelationException or TimeoutException

Current Behavior

See bug desctiption

Reproduction Steps

final DynamoDbTable<EnhancedDocument> table = DynamoDbEnhancedClient.create()
        .table(
                "<table-name>",
                TableSchema.documentSchemaBuilder()
                        .addIndexPartitionKey(TableMetadata.primaryIndexName(), "<primary partition key>", AttributeValueType.N)
                        .addIndexSortKey(TableMetadata.primaryIndexName(), "<primary sorting key>", AttributeValueType.S)
                        .build()
        );

try (ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor()) {
    final List<Future<EnhancedDocument>> futures = executorService.invokeAll(
            List.of(() -> table.getItem(Key.builder()
                    .partitionValue(123)
                    .sortValue("456")
                    .build())),
            5,
            TimeUnit.SECONDS
    );
    System.out.println(futures.getFirst().get());
} catch (ExecutionException | InterruptedException e) {
    throw new RuntimeException(e);
}

But, when using Executors.newThreadPerTaskExecutor(Thread.ofPlatform().factory()), this doesn't happen, in addition, when deploying our code to production (using virtual threads), on Ubuntu Server 22.04 EC2s, this doesn't happen either.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.20.157

JDK version used

openjdk 21.0.3 2024-04-16 LTS
OpenJDK Runtime Environment Corretto-21.0.3.9.1 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.3.9.1 (build 21.0.3+9-LTS, mixed mode, sharing)

Operating System and version

MacOS 14.4.1

@ashr123 ashr123 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 28, 2024
@ashr123
Copy link
Author

ashr123 commented Jun 5, 2024

Never mind, I've havn't been able to recreate this error in an independent project, but I've discovered that since SDK v2.22 there is new HTTP client called AwsCrtHttpClient that uses non-blocking I/O (in contrast of the default ApacheHttpClient) that is perfect for working with virtual threads, you should update your documentation and reference the methodology of working with virtual threads

@ashr123 ashr123 closed this as completed Jun 5, 2024
Copy link

github-actions bot commented Jun 5, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant