Azure / Azure/DotNetty

asp.net core integration in core cannot close and free up port footprint

Open
#501 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

asp.net core integration in core cannot close and free up port footprint and exit application,
Call edited by
`
lifetime.ApplicationStopping.Register(() =>
{
DI.GetService().Stop();
});
`

`
public void Init(Func handler)
{

if (_options.Value.EventLoopCount > 0)
{
bossGroup = new MultithreadEventLoopGroup(_options.Value.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, _options.Value.MaxPackLength, 65536));
bootstrap.Option(ChannelOption.TcpNodelay, true);
bootstrap.ChildOption(ChannelOption.SoKeepalive, true);
bootstrap.ChildHandler(new ActionChannelInitializer(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
// 添加日志拦截器

pipeline.AddLast(new LoggingHandler("SRV-CONN"));
pipeline.AddLast(new FrameDecoder(ByteOrder.LittleEndian, _options.Value.MaxPackLength, _options.Value.HeadPosition, _options.Value.HeadLength
, _options.Value.LengthAdjustment, _options.Value.InitialBytesToStrip, true));
//pipeline.AddLast(new LengthFieldBasedFrameDecoder(ByteOrder.LittleEndian, _options.Value.MaxPackLength, _options.Value.HeadPosition, _options.Value.HeadLength
// , _options.Value.LengthAdjustment, 0, true));
//pipeline.AddLast("MTPackageDecode", new MTDecoder());
if (_options.Value.Timeout > 0)
{
pipeline.AddLast("ReadTimeout", new ReadTimeoutHandler(_options.Value.Timeout));
}
pipeline.AddLast(handler());
}));
}
public async Task Start()
{
bootstrapChannel =await bootstrap.BindAsync(_options.Value.DevicePort);
}
public void Stop()
{
bootstrapChannel.CloseAsync().Wait(3000);
bossGroup.ShutdownGracefullyAsync().Wait(3000);
workerGroup.ShutdownGracefullyAsync().Wait(3000);
}
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.