From 5157d6fe7f995cc6bc7f1453e63ed8c85100beea Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 24 Oct 2023 09:04:16 +0300 Subject: [PATCH] Stability (#324) * propagate rootcause of JsonRpcException * increase pool size * Log WsConnectionImpl exceptions --- .../dshackle/upstream/ethereum/WsConnectionImpl.kt | 2 +- .../dshackle/upstream/rpcclient/JsonRpcException.kt | 5 ++++- .../dshackle/upstream/rpcclient/JsonRpcHttpClient.kt | 12 ++++-------- .../io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt index 2f63a919..c5893e5d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt @@ -273,7 +273,7 @@ open class WsConnectionImpl( } onMessage(msg) } catch (t: Throwable) { - log.warn("Failed to process WS message. ${t.javaClass}: ${t.message}. Message: ${String(it)}") + log.warn("Failed to process WS message", t) Mono.empty() } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt index 060a4249..8ce2dcaa 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt @@ -22,10 +22,13 @@ open class JsonRpcException( val error: JsonRpcError, val upstreamId: String? = null, writableStackTrace: Boolean = true, -) : Exception(error.message, null, true, writableStackTrace) { + cause: Throwable? = null, +) : Exception(error.message, cause, true, writableStackTrace) { constructor(id: Int, message: String) : this(JsonRpcResponse.NumberId(id), JsonRpcError(-32005, message)) + constructor(id: Int, message: String, cause: Throwable) : this(JsonRpcResponse.NumberId(id), JsonRpcError(-32005, message), cause = cause) + companion object { fun from(err: RpcException): JsonRpcException { val id = err.details?.let { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt index 40b5b8d8..abd9601d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt @@ -25,7 +25,6 @@ import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.ssl.SslContextBuilder import io.netty.resolver.DefaultAddressResolverGroup import org.apache.commons.lang3.time.StopWatch -import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import reactor.netty.http.client.HttpClient import reactor.netty.resources.ConnectionProvider @@ -50,18 +49,15 @@ class JsonRpcHttpClient( tlsCAAuth: ByteArray? = null, ) : JsonRpcReader { - companion object { - private val log = LoggerFactory.getLogger(JsonRpcHttpClient::class.java) - } - private val parser = ResponseRpcParser() private val httpClient: HttpClient init { val connectionProvider = ConnectionProvider.builder("dshackleConnectionPool") - .maxConnections(1000) - .pendingAcquireMaxCount(5000) + .maxConnections(1500) + .pendingAcquireMaxCount(10000) .build() + var build = HttpClient.create(connectionProvider) .compress(true) .resolver(DefaultAddressResolverGroup.INSTANCE) @@ -152,7 +148,7 @@ class JsonRpcHttpClient( val err = when (t) { is RpcException -> JsonRpcException.from(t) is JsonRpcException -> t - else -> JsonRpcException(key.id, t.message ?: t.javaClass.name) + else -> JsonRpcException(key.id, t.message ?: t.javaClass.name, cause = t) } // here we're measure the internal errors, not upstream errors metrics.fails.increment() diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 5c8ab350..3f5bcec2 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -176,7 +176,7 @@ class NativeCallSpec extends Specification { nativeCall.rpcReaderFactory = Mock(RpcReaderFactory) { 1 * create(_) >> Mock(RpcReader) { 1 * read(new JsonRpcRequest("eth_test", [], 10)) >> Mono.error( - new JsonRpcException(JsonRpcResponse.Id.from(12), new JsonRpcError(-32123, "Foo Bar", "Foo Bar Baz"), null, true) + new JsonRpcException(JsonRpcResponse.Id.from(12), new JsonRpcError(-32123, "Foo Bar", "Foo Bar Baz"), null, true, null) ) } }