The number of threads has been increasing and will not be released
- Dominant language
- C#
- Stars
- 4.3k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
I tried to use Netty as DTU TCP Server, but in the process of using it found that the number of threads has been slowly increasing with the running time, but at this time the number of online devices is very small, only about 1-5, why,
My configuration code is as follows
`public void Init(ServerOptions options,Func handler)
{
_options = options;
if (options.EventLoopCount > 0)
{
bossGroup = new MultithreadEventLoopGroup(options.EventLoopCount);
}
else
{
bossGroup = new MultithreadEventLoopGroup();
}
workerGroup = new MultithreadEventLoopGroup();
bootstrap = new ServerBootstrap();
bootstrap.Group(bossGroup, workerGroup);
bootstrap.Channel();
bootstrap.Option(ChannelOption.SoBacklog, _options.SoBacklog);
bootstrap.ChildOption(ChannelOption.RcvbufAllocator,new AdaptiveRecvByteBufAllocator(64,1048,65536));
bootstrap.Option(ChannelOption.TcpNodelay, true);
bootstrap.ChildOption(ChannelOption.SoKeepalive, false);
bootstrap.ChildHandler(new ActionChannelInitializer(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
//pipeline.AddLast(new IdleStateHandler(300, 300, 0));
if (options.ReadTimeout > 0)
{
pipeline.AddLast("ReadTimeout", new ReadTimeoutHandler(options.ReadTimeout));
}
pipeline.AddLast(handler());
}));
}`
Handler code :
` ///
/// socket字节流处理对象
///
public class SocketByteHandler: ChannelHandlerAdapter
{
readonly bool autoRelease;
public SocketByteHandler() : this(true)
{
}
protected SocketByteHandler(bool autoRelease)
{
this.autoRelease = autoRelease;
}
public bool AcceptInboundMessage(object msg) => msg is IByteBuffer;
public override void ChannelRead(IChannelHandlerContext ctx, object msg)
{
bool release = true;
try
{
if (this.AcceptInboundMessage(msg))
{
IByteBuffer imsg = (IByteBuffer)msg;
byte[] result = new byte[imsg.ReadableBytes];
imsg.ReadBytes(result);
this.ChannelRead0(ctx, result);
}
else
{
release = false;
ctx.FireChannelRead(msg);
}
}
finally
{
if (autoRelease && release)
{
ReferenceCountUtil.Release(msg);
}
}
}
protected virtual void ChannelRead0(IChannelHandlerContext ctx,byte[] msg)
{
}
public override void UserEventTriggered(IChannelHandlerContext context, object evt)
{
if(evt is IdleStateEvent)
{
Console.WriteLine(evt.ToString());
IdleStateEvent _event = (IdleStateEvent)evt;
if(_event.State== IdleState.AllIdle)
{
}
}
}
}`

Contributor guide
Assessment
This issue has not been assessed yet.