diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/HttpRequestRetry.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/HttpRequestRetry.kt index 6f55aae501c..a0fef6e25b3 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/HttpRequestRetry.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/HttpRequestRetry.kt @@ -327,8 +327,11 @@ public class HttpRequestRetry internal constructor(configuration: Configuration) private fun prepareRequest(request: HttpRequestBuilder): HttpRequestBuilder { val subRequest = HttpRequestBuilder().takeFrom(request) - val subRequestJob = Job(request.executionContext) - subRequest.executionContext = subRequestJob + request.executionContext.invokeOnCompletion { cause -> + val subRequestJob = subRequest.executionContext as CompletableJob + if (cause == null) subRequestJob.complete() + else subRequestJob.completeExceptionally(cause) + } return subRequest }