Description
Describe the bug
I am running a kotlin KTOR service running on AWS SDK - 2.17.100, Java 11.
The below exception thrown while fetching any of these AWS DdynamDb client, S3Client, CloudWatchMetricPublisher.
Code Snippet:
@Provides @Singleton fun provideSimpleDynamoDbClient(): DynamoDbAsyncClient { return DynamoDbAsyncClient.create() }
@Provides @Singleton fun provideCloudWatchMetricPublisher(): CloudWatchMetricPublisher { return CloudWatchMetricPublisher.builder().apply { namespace(config.getProperty("meterRegistry.cloudwatch.sqs.namespace")) metricLevel(MetricLevel.TRACE) }.build() }
@Provides @Singleton fun provideS3Client(): S3Client = S3ClientImpl( s3AsyncClientWrapper = S3AsyncClientWrapper(S3AsyncClient.create()), )
Error Message: java.net.SocketTimeoutException: Read timed out from this API http://169.254.169.254/latest/api/token
I have added the error trace below, it is having 1second timeout.
I have checked the AWS source files here and here the calls for fetching the token are blocked, and it wont be a configurable value.
I am also adding the the SDK Metrics "CredentialsFetchDuration" below.
I have referred #3448 and they are not as what i am facing.
I have also here, in my case every aws resource is throwing this error.
Please advise on how to fix this issue.
Expected Behavior
The API should handle the error itself, or AWS should give the configurable way to reduce the
Current Behavior
high latency and error rate in the service because of this exception.
Reproduction Steps
AWS SDK 2.17.100
Java - 11
Ktor service,
try to create singleton s3client or dynamodb client and try to use them to send or receive message.
Possible Solution
- instead of throwing this to the caller, the SDK should handle itself and will throw a warning.
- The SDK can provide a configurable timeout.
- Since this is the issue at AWS IMDSv2 they can add about this in documentation.
Additional Information/Context
Error trace:
java.net.SocketTimeoutException: Read timed out
at java.base/java.net.SocketInputStream.socketRead0(Native Method)
at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:292)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:351)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:788)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:723)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1615)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at software.amazon.awssdk.regions.util.HttpResourcesUtils.readResource(HttpResourcesUtils.java:116)
at software.amazon.awssdk.regions.internal.util.EC2MetadataUtils.getToken(EC2MetadataUtils.java:412)
at software.amazon.awssdk.regions.internal.util.EC2MetadataUtils.getItems(EC2MetadataUtils.java:379)
at software.amazon.awssdk.regions.internal.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:348)
at software.amazon.awssdk.regions.internal.util.EC2MetadataUtils.getData(EC2MetadataUtils.java:344)
at software.amazon.awssdk.regions.internal.util.EC2MetadataUtils.getEC2InstanceRegion(EC2MetadataUtils.java:228)
at software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider.tryDetectRegion(InstanceProfileRegionProvider.java:68)
at software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider.getRegion(InstanceProfileRegionProvider.java:52)
at software.amazon.awssdk.regions.providers.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:51)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.regionFromDefaultProvider(AwsDefaultClientBuilder.java:217)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.resolveRegion(AwsDefaultClientBuilder.java:199)
at software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder.finalizeChildConfiguration(AwsDefaultClientBuilder.java:145)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.asyncClientConfiguration(SdkDefaultClientBuilder.java:184)
at software.amazon.awssdk.services.cloudwatch.DefaultCloudWatchAsyncClientBuilder.buildClient(DefaultCloudWatchAsyncClientBuilder.java:29)
at software.amazon.awssdk.services.cloudwatch.DefaultCloudWatchAsyncClientBuilder.buildClient(DefaultCloudWatchAsyncClientBuilder.java:22)
at software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:133)
at software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient.create(CloudWatchAsyncClient.java:142)
AWS Java SDK version used
2.17.100
JDK version used
11
Operating System and version
AWS Linux