Skip to content

Commit

Permalink
Merge pull request quarkusio#31287 from faculbsz-sg/grpc-permit-keep-…
Browse files Browse the repository at this point in the history
…alive

Adding server grpc netty permit-keep-alive-time  and permit-keep-alive-without-calls
  • Loading branch information
cescoffier authored Feb 28, 2023
2 parents fcc117d + 1a716df commit 269da7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ public class GrpcServerNettyConfig {
@ConfigItem
public Optional<Duration> 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<Duration> 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<Boolean> permitKeepAliveWithoutCalls;

}

0 comments on commit 269da7b

Please sign in to comment.