awslabs / aws-sdk-kotlin

Multiplatform AWS SDK for Kotlin
Apache License 2.0
396 stars 49 forks source link

Trouble configuring DynamoDb Client timeout #1316

Closed jonathanwhang closed 3 months ago

jonathanwhang commented 3 months ago

Describe the bug

There's not much documentation surrounding how to configure a timeout on the Dynamo client using aws-sdk-kotlin outside of this page, which implies that HttpEngine properties, which include socketReadTimeout and socketWriteTimeout (see OkHttpEngineConfig) are configurable. What I currently have in my application is the following (using aws.sdk.kotlin.services.dynamodb.DynamoDbClient):

        DynamoDbClient.fromEnvironment {
            region = "us-west-2"
            httpClient {
                socketReadTimeout = 500.milliseconds
                socketWriteTimeout = 500.milliseconds
            }
        }

However, it doesn't appear to be working at the moment as I'm still seeing dynamo operations surpassing 500ms.

There is one additional issue: accessing DynamoDbClient.config.httpClient.config shows double values for socketRead/WriteTimeout. For example, if I set socketReadTimeout to 500.milliseconds, httpClient.config shows the int 1,000,000,000, which in nanoseconds is 1000ms). If I do an explicit get (DynamoDbClient.config.httpClient.config.socketReadTimeout), I get the correct value I set in the form of a Duration.

Docs/examples would be helpful.

Expected behavior

DynamoDBClient cancels operations that exceed the timeout configured in the HttpClient

Current behavior

No operations are cancelled, and the timeout values in the final config do not seem to reflect my inputs

Steps to Reproduce

Instantiate a DynamoDbClient using DynamoDbClient.fromEnvironment { } or DynamoDbClient { } and set the timeout inside httpClient

Possible Solution

No response

Context

No response

AWS SDK for Kotlin version

1.0.67

Platform (JVM/JS/Native)

JVM

Operating system and version

OS Sonoma

lauzadis commented 3 months ago

The doubled values you are seeing seem to be an implementation detail of Java's Duration class. When setting a timeout duration of 30ms, I can see the rawValue field is 60000000, but the duration.inWholeMilliseconds method returns the expected value of 30.

I'm also not able to replicate the issue you're having with timeouts not being respected. Setting socketReadTimeout to 30 milliseconds consistently results in timeouts when I call DynamoDB ListTables operation.

Can you provide a detailed reproduction case? What are your timeout values, what operations are you invoking? As a sanity check, you can try setting a very low timeout to see if it is respected.

jonathanwhang commented 3 months ago

Hi @lauzadis, thanks for picking this up. Did a sanity check and confirmed that the configs do seem to work, it was just a misunderstanding on my part (timeout values needed to be lower). Closing this ticket.

github-actions[bot] commented 3 months ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.