Add keep-alive to grpc server (fixes clients ws cancellation when no data passed) (#468)

This commit is contained in:
msizov
2024-05-07 19:23:31 +07:00
committed by GitHub
parent 65c383ac69
commit a724ce2acf
2 changed files with 10 additions and 0 deletions

View File

@@ -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
}
}

View File

@@ -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)