增加TCP超时释放,解决运行一段时间netty打开连接数不断增长的bug

This commit is contained in:
weidong 2024-06-13 14:36:59 +08:00
parent 93c7d9036a
commit cd8184e41b

View File

@ -6,7 +6,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.ReadTimeoutHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -40,6 +40,7 @@ public class RtcmTcpServer implements ApplicationRunner {
@Override @Override
protected void initChannel(Channel channel) throws Exception { protected void initChannel(Channel channel) throws Exception {
ChannelPipeline p = channel.pipeline(); ChannelPipeline p = channel.pipeline();
p.addLast(new ReadTimeoutHandler(600));
//p.addLast(new IdleStateHandler(600, 600, 600)); //设置心跳超时时间 //p.addLast(new IdleStateHandler(600, 600, 600)); //设置心跳超时时间
p.addLast(new RtcmTcpHandler()); p.addLast(new RtcmTcpHandler());
} }