From 1ea6345cd6f5484129d6f3d457006fa7e2fe1c0c Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Fri, 6 Sep 2019 01:29:10 -0400 Subject: [PATCH] problem: upstream which didn't respond to head block is available for calls, may fail solution: mark as unavailable immediately after head request error --- .../io/emeraldpay/dshackle/upstream/grpc/GrpcUpstream.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstream.kt index f6c967cd..3aa18469 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstream.kt @@ -41,6 +41,7 @@ import java.lang.Exception import java.math.BigInteger import java.time.Duration import java.util.* +import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicReference import java.util.function.Function import kotlin.collections.ArrayList @@ -122,10 +123,11 @@ open class GrpcUpstream( }.flatMap { getApi(Selector.EmptyMatcher()) .flatMap { api -> api.executeAndConvert(Commands.eth().getBlock(it.hash)) } - .timeout(Duration.ofSeconds(5), Mono.error(Exception("Timeout requesting block from upstream"))) + .timeout(Duration.ofSeconds(5), Mono.error(TimeoutException("Timeout from upstream"))) .doOnError { t -> - val msg = "Failed to download block data for chain $chain" - if (t is RpcException) { + setStatus(UpstreamAvailability.UNAVAILABLE) + val msg = "Failed to download block data for chain $chain on $parentId" + if (t is RpcException || t is TimeoutException) { log.warn("$msg. Message: ${t.message}") } else { log.error(msg, t)