smithy-lang / smithy-kotlin

Smithy code generator for Kotlin (in development)
Apache License 2.0
77 stars 26 forks source link

fix: cancel `HttpCall` if closing the response body fails #938

Closed lauzadis closed 1 year ago

lauzadis commented 1 year ago

See https://github.com/awslabs/smithy-kotlin/issues/935 for the full context.

This PR fixes an IllegalStateException that's thrown when trying to close the engineResponse.body while a different coroutine is blocked trying to read() the body.

The fix works by checking if closing the response body fails (throwing IllegalStateException). If it fails, then we can first cancel the Call (as recommended by OkHttp devs), wait a short period of time, and then close the response body successfully.

Issue \

Closes https://github.com/awslabs/smithy-kotlin/issues/935

Description of changes

This change is required to support closing event streams before they have been fully consumed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

lauzadis commented 1 year ago

Fixed by https://github.com/awslabs/smithy-kotlin/pull/939