mirror of
https://github.com/corda/corda.git
synced 2025-03-14 00:06:45 +00:00
ENT-1962: Perform RPC retry in case of RejectedCommandException (#982)
* ENT-1962: Perform RPC retry in case of RejectedCommandException (cherry picked from commit 2a7f0dd) * ENT-1962: Address code-review comments. (cherry picked from commit 7b4edde)
This commit is contained in:
parent
eaf7adab20
commit
1011e45b84
@ -45,6 +45,7 @@ dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
|
||||
cordaCompile project(":client:rpc")
|
||||
cordaCompile project(':node-api')
|
||||
cordaCompile project(":finance")
|
||||
cordaCompile project(":perftestcordapp")
|
||||
|
||||
|
@ -12,6 +12,7 @@ import net.corda.core.node.services.vault.Sort
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.minutes
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.nodeapi.exceptions.RejectedCommandException
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.time.Duration
|
||||
@ -57,13 +58,19 @@ fun <T> arithmeticBackoff(retryInterval: Duration, giveUpInterval: Duration, mea
|
||||
val start = System.currentTimeMillis()
|
||||
var iterCount = 0
|
||||
|
||||
fun doOnException(ex: Exception) {
|
||||
logger.warn("Exception $meaningfulDescription, iteration #$iterCount", ex)
|
||||
Thread.sleep(iterCount * retryInterval.toMillis())
|
||||
}
|
||||
|
||||
do {
|
||||
try {
|
||||
iterCount++
|
||||
return op()
|
||||
} catch (ex: RPCException) {
|
||||
logger.warn("Exception $meaningfulDescription, iteration #$iterCount", ex)
|
||||
Thread.sleep(iterCount * retryInterval.toMillis())
|
||||
doOnException(ex)
|
||||
} catch (ex: RejectedCommandException) {
|
||||
doOnException(ex)
|
||||
}
|
||||
} while ((System.currentTimeMillis() - start) < giveUpInterval.toMillis())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user