Got an exception:" An existing connection was forcibly closed by the remote host...."
- Dominant language
- C#
- Stars
- 4.3k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
When I initiative disconnected TCP connection from client side, then I got an exception:
Exception: System.Net.Sockets.SocketException (0x80004005): An existing connection was forcibly closed by the remote host
at DotNetty.Transport.Channels.Sockets.SocketChannelAsyncOperation.Validate()
at DotNetty.Transport.Channels.Sockets.AbstractSocketByteChannel.SocketByteChannelUnsafe.FinishRead(SocketChannelAsyncOperation operation)
How can I avoid this exception?
Below is my code snippet:
` try
{
serverBootstrap
.Group(bossGroup, workerGroup)
.Channel()
.Option(ChannelOption.SoBacklog, 200)
.Handler(new MainHandler())
.ChildHandler(
new ActionChannelInitializer(
channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
pipeline.AddLast(new ByteArrayDecoder());
pipeline.AddLast(new ByteArrayEncoder());
pipeline.AddLast(new DotnettyServerHandler());
pipeline.AddLast(new SendRabbitMqHandler());
pipeline.AddLast("heartbeat",
new IdleStateHandler(TimeSpan.FromMinutes(_clientTimeout), TimeSpan.FromMinutes(_clientTimeout),
TimeSpan.FromMinutes(_clientTimeout)));
pipeline.AddLast(new HeartBeatServerHandler());
}));
IChannel boundChannel = await serverBootstrap.BindAsync(port);
Console.WriteLine($"Server started port:{port}");`
Contributor guide
Assessment
This issue has not been assessed yet.