diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt b/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt index 37f2b7bf..ee2b51fe 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt @@ -26,5 +26,9 @@ class Defaults { val timeout: Duration = Duration.ofSeconds(60) val timeoutInternal: Duration = timeout.dividedBy(4) val retryConnection: Duration = Duration.ofSeconds(10) + val grpcServerKeepAliveTime: Long = 15 // seconds + val grpcServerKeepAliveTimeout: Long = 5 + val grpcServerPermitKeepAliveTime: Long = 15 + val grpcServerMaxConnectionIdle: Long = 3600 } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt index 63ebdfd9..2e9136ba 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt @@ -35,6 +35,7 @@ import org.springframework.scheduling.concurrent.CustomizableThreadFactory import org.springframework.stereotype.Service import java.net.InetSocketAddress import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit import javax.annotation.PostConstruct import javax.annotation.PreDestroy @@ -74,6 +75,11 @@ open class GrpcServer( .forAddress(InetSocketAddress(mainConfig.host, mainConfig.port)) .maxInboundMessageSize(Defaults.maxMessageSize) .maxInboundMetadataSize(maxMetadataSize) + .keepAliveTime(Defaults.grpcServerKeepAliveTime, TimeUnit.SECONDS) + .keepAliveTimeout(Defaults.grpcServerKeepAliveTimeout, TimeUnit.SECONDS) + .permitKeepAliveTime(Defaults.grpcServerPermitKeepAliveTime, TimeUnit.SECONDS) + .permitKeepAliveWithoutCalls(true) + .maxConnectionIdle(Defaults.grpcServerMaxConnectionIdle, TimeUnit.SECONDS) if (mainConfig.accessLogConfig.enabled) { serverBuilder.intercept(accessHandler)