Skip to content

Commit 5895358

Browse files
authored
fix: correctly mark more CRT exceptions as retriable (#1142)
1 parent 9d4e6ae commit 5895358

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "1d38a75d-17ac-4e03-b287-f937356bd525",
3+
"type": "bugfix",
4+
"description": "Correctly mark more CRT exceptions as retriable"
5+
}

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ internal class ConnectionManager(
7777
}
7878
val httpEx = when (ex) {
7979
is HttpException -> ex
80-
is TimeoutCancellationException -> HttpException("timed out waiting for an HTTP connection to be acquired from the pool", errorCode = HttpErrorCode.CONNECTION_ACQUIRE_TIMEOUT)
81-
else -> HttpException(ex)
80+
is TimeoutCancellationException -> HttpException(
81+
"timed out waiting for an HTTP connection to be acquired from the pool",
82+
errorCode = HttpErrorCode.CONNECTION_ACQUIRE_TIMEOUT,
83+
retryable = true,
84+
)
85+
else -> HttpException(ex, retryable = true)
8286
}
8387

8488
throw httpEx

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/RequestUtil.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,19 @@ internal suspend fun HttpStream.sendChunkedBody(body: HttpBody) {
119119
}
120120
}
121121

122+
internal fun crtException(errorCode: Int, errorName: String? = CRT.errorName(errorCode), cause: Throwable? = null) =
123+
HttpException(
124+
message = fmtCrtErrorMessage(errorCode),
125+
cause = cause,
126+
errorCode = mapCrtErrorCode(errorName),
127+
retryable = isRetryable(errorCode, errorName),
128+
)
129+
122130
internal inline fun <T> mapCrtException(block: () -> T): T =
123131
try {
124132
block()
125133
} catch (ex: CrtRuntimeException) {
126-
throw HttpException(
127-
message = fmtCrtErrorMessage(ex.errorCode),
128-
errorCode = mapCrtErrorCode(ex.errorName),
129-
retryable = isRetryable(ex.errorCode, ex.errorName),
130-
)
134+
throw crtException(ex.errorCode, ex.errorName, ex)
131135
}
132136

133137
internal fun fmtCrtErrorMessage(errorCode: Int): String {

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ package aws.smithy.kotlin.runtime.http.engine.crt
77

88
import aws.sdk.kotlin.crt.http.*
99
import aws.sdk.kotlin.crt.io.Buffer
10-
import aws.smithy.kotlin.runtime.http.*
1110
import aws.smithy.kotlin.runtime.http.HeadersBuilder
12-
import aws.smithy.kotlin.runtime.http.HttpException
11+
import aws.smithy.kotlin.runtime.http.HttpBody
12+
import aws.smithy.kotlin.runtime.http.HttpStatusCode
13+
import aws.smithy.kotlin.runtime.http.isInformational
1314
import aws.smithy.kotlin.runtime.http.response.HttpResponse
1415
import aws.smithy.kotlin.runtime.io.SdkBuffer
1516
import aws.smithy.kotlin.runtime.io.SdkByteChannel
@@ -18,8 +19,10 @@ import aws.smithy.kotlin.runtime.telemetry.logging.logger
1819
import aws.smithy.kotlin.runtime.util.derivedName
1920
import kotlinx.atomicfu.locks.reentrantLock
2021
import kotlinx.atomicfu.locks.withLock
21-
import kotlinx.coroutines.*
22+
import kotlinx.coroutines.DelicateCoroutinesApi
23+
import kotlinx.coroutines.GlobalScope
2224
import kotlinx.coroutines.channels.Channel
25+
import kotlinx.coroutines.launch
2326
import kotlin.coroutines.CoroutineContext
2427

2528
/**
@@ -178,7 +181,7 @@ internal class SdkStreamResponseHandler(
178181

179182
// close the body channel
180183
if (errorCode != 0) {
181-
val ex = HttpException(fmtCrtErrorMessage(errorCode), errorCode = mapCrtErrorCode(errorCode))
184+
val ex = crtException(errorCode)
182185
responseReady.close(ex)
183186
bodyChan.close(ex)
184187
} else {

0 commit comments

Comments
 (0)