From f791aa98ff909cd32ca7b69529ab71985057f1ed Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Thu, 25 Aug 2022 17:08:53 -0400 Subject: [PATCH] problem: reconnects too fast to a faulty WS connection --- .../dshackle/upstream/ethereum/WsConnection.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt index a6befbc0..54ac488f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -225,12 +225,18 @@ open class WsConnection( } fun handle(inbound: WebsocketInbound, outbound: WebsocketOutbound): Publisher { - // restart backoff after connection - currentBackOff = reconnectBackoff.start() - + var read = false val consumer = inbound .aggregateFrames(msgSizeLimit) .receiveFrames() + .doOnNext { + if (!read) { + // restart backoff only after a successful read from the connection, + // otherwise it may restart it even if the connection is faulty + currentBackOff = reconnectBackoff.start() + read = true + } + } .map { ByteBufInputStream(it.content()).readAllBytes() } .flatMap { try {