Azure / Azure/DotNetty

Got an exception:" An existing connection was forcibly closed by the remote host...."

Open
#357 1 comment 0 reactions 0 assignees View on GitHub
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

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.