From 1a716df0d7c409e367cf5f40f91a59c047e6d98f Mon Sep 17 00:00:00 2001 From: faculbsz Date: Sun, 19 Feb 2023 18:12:59 +0100 Subject: [PATCH] feat: add server grpc netty permit-keep-alive-time and permit-keep-alive-without-calls as configuration options --- .../grpc/runtime/GrpcServerRecorder.java | 11 +++++++++-- .../runtime/config/GrpcServerNettyConfig.java | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java index a029be34042e2..8465e4387bae1 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/GrpcServerRecorder.java @@ -36,6 +36,7 @@ import io.grpc.ServerInterceptors; import io.grpc.ServerMethodDefinition; import io.grpc.ServerServiceDefinition; +import io.grpc.netty.NettyServerBuilder; import io.quarkus.arc.Arc; import io.quarkus.arc.InstanceHandle; import io.quarkus.arc.Subclass; @@ -299,8 +300,14 @@ private void devModeStart(GrpcContainer grpcContainer, Vertx vertx, GrpcServerCo private void applyNettySettings(GrpcServerConfiguration configuration, VertxServerBuilder builder) { if (configuration.netty != null) { GrpcServerNettyConfig config = configuration.netty; - config.keepAliveTime.ifPresent(duration -> builder.nettyBuilder() - .keepAliveTime(duration.toNanos(), TimeUnit.NANOSECONDS)); + NettyServerBuilder nettyServerBuilder = builder.nettyBuilder(); + + config.keepAliveTime.ifPresent( + duration -> nettyServerBuilder.keepAliveTime(duration.toNanos(), TimeUnit.NANOSECONDS)); + + config.permitKeepAliveTime.ifPresent( + duration -> nettyServerBuilder.permitKeepAliveTime(duration.toNanos(), TimeUnit.NANOSECONDS)); + config.permitKeepAliveWithoutCalls.ifPresent(nettyServerBuilder::permitKeepAliveWithoutCalls); } } diff --git a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java index dc7c78f36a2f5..12f491389fabe 100644 --- a/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java +++ b/extensions/grpc/runtime/src/main/java/io/quarkus/grpc/runtime/config/GrpcServerNettyConfig.java @@ -17,4 +17,21 @@ public class GrpcServerNettyConfig { @ConfigItem public Optional keepAliveTime; + /** + * Sets a custom permit-keep-alive duration. This configures the most aggressive keep-alive time clients + * are permitted to configure. + * The server will try to detect clients exceeding this rate and when detected will forcefully close the connection. + * + * @see #permitKeepAliveWithoutCalls + */ + @ConfigItem + public Optional permitKeepAliveTime; + + /** + * Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if + * there are no outstanding RPCs on the connection. + */ + @ConfigItem + public Optional permitKeepAliveWithoutCalls; + }