Skip to content

Commit 15a3009

Browse files
authored
Use Stricter Retry Logic in ApacheBlockingContainerClient (#4141)
* Use Stricter Retry Logic in ApacheBlockingContainerClient * Scala Format * Update Tests * Simplify timeout calculation * Remove max retry threshold * Remove unneeded variable * Remove unnecessary type conversion * Add comment for sleep units
1 parent f1ccdba commit 15a3009

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

common/scala/src/main/scala/org/apache/openwhisk/core/containerpool/ApacheBlockingContainerClient.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.openwhisk.core.containerpool
1919

2020
import java.net.NoRouteToHostException
2121
import java.nio.charset.StandardCharsets
22+
import java.time.Instant
2223

2324
import org.apache.commons.io.IOUtils
2425
import org.apache.http.HttpHeaders
@@ -105,6 +106,8 @@ protected class ApacheBlockingContainerClient(hostname: String,
105106
// Annotation will make the compiler complain if no tail recursion is possible
106107
@tailrec private def execute(request: HttpRequestBase, timeout: FiniteDuration, maxConcurrent: Int, retry: Boolean)(
107108
implicit tid: TransactionId): Either[ContainerHttpError, ContainerResponse] = {
109+
val start = Instant.now
110+
108111
Try(connection.execute(request)).map { response =>
109112
val containerResponse = Option(response.getEntity)
110113
.map { entity =>
@@ -149,10 +152,9 @@ protected class ApacheBlockingContainerClient(hostname: String,
149152
} match {
150153
case Success(response) => response
151154
case Failure(t: RetryableConnectionError) if retry =>
152-
val sleepTime = 50.milliseconds
153155
if (timeout > Duration.Zero) {
154-
Thread.sleep(sleepTime.toMillis)
155-
val newTimeout = timeout - sleepTime
156+
Thread.sleep(50) // Sleep for 50 milliseconds
157+
val newTimeout = timeout - (Instant.now.toEpochMilli - start.toEpochMilli).milliseconds
156158
execute(request, newTimeout, maxConcurrent, retry = true)
157159
} else {
158160
logging.warn(this, s"POST failed with $t - no retry because timeout exceeded.")

0 commit comments

Comments
 (0)