Merge pull request #48 from p2p-org/fix_gRPC_message_size_limit
Fix grpc message size limit
This commit is contained in:
@@ -36,7 +36,7 @@ group = 'io.emeraldpay.dshackle'
|
|||||||
// Version schema:
|
// Version schema:
|
||||||
// x.x.x for production, following SemVer model
|
// x.x.x for production, following SemVer model
|
||||||
// x.x.x-SNAPSHOT for development
|
// x.x.x-SNAPSHOT for development
|
||||||
version = '0.15.0-SNAPSHOT'
|
version = '0.16.0-SNAPSHOT'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_13
|
sourceCompatibility = JavaVersion.VERSION_13
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.time.Duration
|
|||||||
class Defaults {
|
class Defaults {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val maxMessageSize: Int = 32 * 1024 * 1024
|
||||||
val timeout: Duration = Duration.ofSeconds(60)
|
val timeout: Duration = Duration.ofSeconds(60)
|
||||||
val timeoutInternal: Duration = timeout.dividedBy(4)
|
val timeoutInternal: Duration = timeout.dividedBy(4)
|
||||||
val retryConnection: Duration = Duration.ofSeconds(10)
|
val retryConnection: Duration = Duration.ofSeconds(10)
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ open class GrpcServer(
|
|||||||
log.info("Listening Native gRPC on ${mainConfig.host}:${mainConfig.port}")
|
log.info("Listening Native gRPC on ${mainConfig.host}:${mainConfig.port}")
|
||||||
val serverBuilder = NettyServerBuilder
|
val serverBuilder = NettyServerBuilder
|
||||||
.forAddress(InetSocketAddress(mainConfig.host, mainConfig.port))
|
.forAddress(InetSocketAddress(mainConfig.host, mainConfig.port))
|
||||||
|
.maxInboundMessageSize(Defaults.maxMessageSize)
|
||||||
.let {
|
.let {
|
||||||
if (mainConfig.accessLogConfig.enabled) {
|
if (mainConfig.accessLogConfig.enabled) {
|
||||||
it.intercept(accessHandler)
|
it.intercept(accessHandler)
|
||||||
@@ -65,7 +66,7 @@ open class GrpcServer(
|
|||||||
val server = serverBuilder.build()
|
val server = serverBuilder.build()
|
||||||
this.server = server
|
this.server = server
|
||||||
|
|
||||||
Thread { server.start() }.run()
|
server.start()
|
||||||
log.info("GRPC Server started")
|
log.info("GRPC Server started")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import io.emeraldpay.dshackle.upstream.DefaultUpstream
|
|||||||
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
|
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient
|
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient
|
||||||
import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics
|
import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics
|
||||||
import io.grpc.ManagedChannelBuilder
|
|
||||||
import io.grpc.netty.NettyChannelBuilder
|
import io.grpc.netty.NettyChannelBuilder
|
||||||
import io.micrometer.core.instrument.Counter
|
import io.micrometer.core.instrument.Counter
|
||||||
import io.micrometer.core.instrument.Metrics
|
import io.micrometer.core.instrument.Metrics
|
||||||
@@ -70,21 +69,21 @@ class GrpcUpstreams(
|
|||||||
private val lock = ReentrantLock()
|
private val lock = ReentrantLock()
|
||||||
|
|
||||||
fun start(): Flux<UpstreamChangeEvent> {
|
fun start(): Flux<UpstreamChangeEvent> {
|
||||||
val channel: ManagedChannelBuilder<*> = if (auth != null && StringUtils.isNotEmpty(auth.ca)) {
|
val chanelBuilder = NettyChannelBuilder.forAddress(host, port)
|
||||||
NettyChannelBuilder.forAddress(host, port)
|
|
||||||
// some messages are very large. many of them in megabytes, some even in gigabytes (ex. ETH Traces)
|
// some messages are very large. many of them in megabytes, some even in gigabytes (ex. ETH Traces)
|
||||||
.maxInboundMessageSize(Int.MAX_VALUE)
|
.maxInboundMessageSize(Defaults.maxMessageSize)
|
||||||
.useTransportSecurity()
|
|
||||||
.enableRetry()
|
.enableRetry()
|
||||||
.maxRetryAttempts(3)
|
.maxRetryAttempts(3)
|
||||||
|
if (auth != null && StringUtils.isNotEmpty(auth.ca)) {
|
||||||
|
chanelBuilder
|
||||||
|
.useTransportSecurity()
|
||||||
.sslContext(withTls(auth))
|
.sslContext(withTls(auth))
|
||||||
} else {
|
} else {
|
||||||
log.warn("Using insecure connection to $host:$port")
|
log.warn("Using insecure connection to $host:$port")
|
||||||
ManagedChannelBuilder.forAddress(host, port)
|
chanelBuilder.usePlaintext()
|
||||||
.usePlaintext()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val client = ReactorBlockchainGrpc.newReactorStub(channel.build())
|
val client = ReactorBlockchainGrpc.newReactorStub(chanelBuilder.build())
|
||||||
this.client = client
|
this.client = client
|
||||||
|
|
||||||
val statusSubscription = AtomicReference<Disposable>()
|
val statusSubscription = AtomicReference<Disposable>()
|
||||||
|
|||||||
Reference in New Issue
Block a user