diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java index cd085f9590..db9956a6d4 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java @@ -161,6 +161,14 @@ public synchronized CompletableFuture start() throws Exce channelizer = createChannelizer(settings); channelizer.init(serverGremlinExecutor); + // When the channelizer does not support idle monitoring, enable the ChannelOption.SO_KEEPALIVE feature. + if (!channelizer.supportsIdleMonitor()) { + // Enable TCP Keep-Alive to detect if the remote peer is still reachable. + // Keep-Alive sends periodic probes to check if the remote peer is still active. + // If the remote peer is unreachable, the connection will be closed, preventing resource leaks and + // avoiding the maintenance of stale connections. + b.childOption(ChannelOption.SO_KEEPALIVE, true); + } b.group(bossGroup, workerGroup) .childHandler(channelizer); if (isEpollEnabled){