Closed madisp closed 5 months ago
Running lots of SQS client calls in parallel throws java.lang.IllegalStateException at AsyncTimeout.kt:58 when canceling the scope. Follow-up on my last few comments in #962 .
java.lang.IllegalStateException at AsyncTimeout.kt:58
Exception not thrown
Exception thrown :)
Start with an empty c7gd.xlarge instance running ami-0c5789c17ae99a2fa
c7gd.xlarge
ami-0c5789c17ae99a2fa
Install java and docker:
sudo apt install default-jdk sudo snap install docker sudo groupadd docker sudo usermod -aG docker $USER
(Reboot the ec2 instance at this point)
Clone the example project and run the tests:
git clone https://github.com/madisp/aws-kotlin-threads.git cd aws-kotlin-threads ./gradlew test
I think the issue is the Job#invokeOnCompletion call here - https://github.com/smithy-lang/smithy-kotlin/blob/5dddc09697d2dfc2c883f7a963392428e7338b8f/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/src/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpEngine.kt#L54. The completion handler will probably be called on the dispatcher thread of whoever is doing the cancel. ResponseBody.close will try to consume any unconsumed bytes and this can lead to multiple threads working with the same ResponseBody, correctly triggering a precondition check failure in AsyncTimeout.
Job#invokeOnCompletion
ResponseBody.close
ResponseBody
AsyncTimeout
I'm using aws-sdk-kotlin in a backend project and was experimenting with the limits of SQS clients in a single process.
aws-sdk-kotlin
Describe the bug
Running lots of SQS client calls in parallel throws
java.lang.IllegalStateException at AsyncTimeout.kt:58
when canceling the scope. Follow-up on my last few comments in #962 .Expected Behavior
Exception not thrown
Current Behavior
Exception thrown :)
Steps to Reproduce
Start with an empty
c7gd.xlarge
instance runningami-0c5789c17ae99a2fa
Install java and docker:
(Reboot the ec2 instance at this point)
Clone the example project and run the tests:
Possible Solution
I think the issue is the
Job#invokeOnCompletion
call here - https://github.com/smithy-lang/smithy-kotlin/blob/5dddc09697d2dfc2c883f7a963392428e7338b8f/runtime/protocol/http-client-engines/http-client-engine-okhttp/jvm/src/aws/smithy/kotlin/runtime/http/engine/okhttp/OkHttpEngine.kt#L54. The completion handler will probably be called on the dispatcher thread of whoever is doing the cancel.ResponseBody.close
will try to consume any unconsumed bytes and this can lead to multiple threads working with the sameResponseBody
, correctly triggering a precondition check failure inAsyncTimeout
.Context
I'm using
aws-sdk-kotlin
in a backend project and was experimenting with the limits of SQS clients in a single process.Your Environment
c7gd.xlarge
.