Skip to content

Commit

Permalink
fix: correctly mark more CRT exceptions as retriable (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianbotsf authored Aug 23, 2024
1 parent 9d4e6ae commit 5895358
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changes/1d38a75d-17ac-4e03-b287-f937356bd525.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1d38a75d-17ac-4e03-b287-f937356bd525",
"type": "bugfix",
"description": "Correctly mark more CRT exceptions as retriable"
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ internal class ConnectionManager(
}
val httpEx = when (ex) {
is HttpException -> ex
is TimeoutCancellationException -> HttpException("timed out waiting for an HTTP connection to be acquired from the pool", errorCode = HttpErrorCode.CONNECTION_ACQUIRE_TIMEOUT)
else -> HttpException(ex)
is TimeoutCancellationException -> HttpException(
"timed out waiting for an HTTP connection to be acquired from the pool",
errorCode = HttpErrorCode.CONNECTION_ACQUIRE_TIMEOUT,
retryable = true,
)
else -> HttpException(ex, retryable = true)
}

throw httpEx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,19 @@ internal suspend fun HttpStream.sendChunkedBody(body: HttpBody) {
}
}

internal fun crtException(errorCode: Int, errorName: String? = CRT.errorName(errorCode), cause: Throwable? = null) =
HttpException(
message = fmtCrtErrorMessage(errorCode),
cause = cause,
errorCode = mapCrtErrorCode(errorName),
retryable = isRetryable(errorCode, errorName),
)

internal inline fun <T> mapCrtException(block: () -> T): T =
try {
block()
} catch (ex: CrtRuntimeException) {
throw HttpException(
message = fmtCrtErrorMessage(ex.errorCode),
errorCode = mapCrtErrorCode(ex.errorName),
retryable = isRetryable(ex.errorCode, ex.errorName),
)
throw crtException(ex.errorCode, ex.errorName, ex)
}

internal fun fmtCrtErrorMessage(errorCode: Int): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package aws.smithy.kotlin.runtime.http.engine.crt

import aws.sdk.kotlin.crt.http.*
import aws.sdk.kotlin.crt.io.Buffer
import aws.smithy.kotlin.runtime.http.*
import aws.smithy.kotlin.runtime.http.HeadersBuilder
import aws.smithy.kotlin.runtime.http.HttpException
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.isInformational
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.io.SdkBuffer
import aws.smithy.kotlin.runtime.io.SdkByteChannel
Expand All @@ -18,8 +19,10 @@ import aws.smithy.kotlin.runtime.telemetry.logging.logger
import aws.smithy.kotlin.runtime.util.derivedName
import kotlinx.atomicfu.locks.reentrantLock
import kotlinx.atomicfu.locks.withLock
import kotlinx.coroutines.*
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/**
Expand Down Expand Up @@ -178,7 +181,7 @@ internal class SdkStreamResponseHandler(

// close the body channel
if (errorCode != 0) {
val ex = HttpException(fmtCrtErrorMessage(errorCode), errorCode = mapCrtErrorCode(errorCode))
val ex = crtException(errorCode)
responseReady.close(ex)
bodyChan.close(ex)
} else {
Expand Down

0 comments on commit 5895358

Please sign in to comment.