diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/LocalTtyServerInitializer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/LocalTtyServerInitializer.java index 195ce8a46..6b99db78d 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/LocalTtyServerInitializer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/LocalTtyServerInitializer.java @@ -42,7 +42,7 @@ public class LocalTtyServerInitializer extends ChannelInitializer pipeline.addLast(new HttpObjectAggregator(ArthasConstants.MAX_HTTP_CONTENT_LENGTH)); pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, null, false, ArthasConstants.MAX_HTTP_CONTENT_LENGTH, false, true)); - pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); + pipeline.addLast(new IdleStateHandler(0, ArthasConstants.WEBSOCKET_IDLE_SECONDS, 0)); pipeline.addLast(new TtyWebSocketFrameHandler(group, handler)); } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java index f293612d7..1c136e614 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/TtyServerInitializer.java @@ -44,7 +44,7 @@ public class TtyServerInitializer extends ChannelInitializer { pipeline.addLast(new BasicHttpAuthenticatorHandler(httpSessionManager)); pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, null, false, ArthasConstants.MAX_HTTP_CONTENT_LENGTH, false, true)); - pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); + pipeline.addLast(new IdleStateHandler(0, ArthasConstants.WEBSOCKET_IDLE_SECONDS, 0)); pipeline.addLast(new TtyWebSocketFrameHandler(group, handler)); } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java index 415005dbd..a373a25ab 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/httptelnet/ProtocolDetectHandler.java @@ -95,7 +95,7 @@ public class ProtocolDetectHandler extends ChannelInboundHandlerAdapter { pipeline.addLast(new BasicHttpAuthenticatorHandler(httpSessionManager)); pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH)); pipeline.addLast(new WebSocketServerProtocolHandler(ArthasConstants.DEFAULT_WEBSOCKET_PATH, null, false, ArthasConstants.MAX_HTTP_CONTENT_LENGTH, false, true)); - pipeline.addLast(new IdleStateHandler(0, 0, ArthasConstants.WEBSOCKET_IDLE_SECONDS)); + pipeline.addLast(new IdleStateHandler(0, ArthasConstants.WEBSOCKET_IDLE_SECONDS, 0)); pipeline.addLast(new TtyWebSocketFrameHandler(channelGroup, ttyConnectionFactory)); ctx.fireChannelActive(); } diff --git a/core/src/test/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandlerQuietTest.java b/core/src/test/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandlerQuietTest.java index fdb0176cf..c6bb257d8 100644 --- a/core/src/test/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandlerQuietTest.java +++ b/core/src/test/java/com/taobao/arthas/core/shell/term/impl/http/TtyWebSocketFrameHandlerQuietTest.java @@ -5,7 +5,9 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.group.DefaultChannelGroup; +import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; import io.netty.util.concurrent.GlobalEventExecutor; import org.junit.jupiter.api.Test; @@ -46,6 +48,26 @@ class TtyWebSocketFrameHandlerQuietTest { assertThat(channel.isOpen()).isFalse(); } + @Test + void writerIdleShouldSendWebSocketPingFrame() { + EmbeddedChannel channel = new EmbeddedChannel(new TtyWebSocketFrameHandler( + new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), + connection -> { + })); + + channel.pipeline().fireUserEventTriggered(IdleStateEvent.WRITER_IDLE_STATE_EVENT); + + PingWebSocketFrame ping = channel.readOutbound(); + try { + assertThat(ping).isNotNull(); + } finally { + if (ping != null) { + ping.release(); + } + channel.finishAndReleaseAll(); + } + } + @Test void extSessionsShouldCarryQuietFlag() { Map extSessions = new ExtHttpTtyConnection(null, true).extSessions();