mirror of
https://github.com/alibaba/arthas.git
synced 2026-10-21 04:42:31 +00:00
Use writer-idle websocket ping (#3225)
This commit is contained in:
+1
-1
@@ -42,7 +42,7 @@ public class LocalTtyServerInitializer extends ChannelInitializer<LocalChannel>
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class TtyServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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();
|
||||
}
|
||||
|
||||
+22
@@ -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<String, Object> extSessions = new ExtHttpTtyConnection(null, true).extSessions();
|
||||
|
||||
Reference in New Issue
Block a user