Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

严重bug,远程主机强迫关闭现有连接 #767

Open
loveyeguo opened this issue Dec 13, 2024 · 7 comments
Open

严重bug,远程主机强迫关闭现有连接 #767

loveyeguo opened this issue Dec 13, 2024 · 7 comments

Comments

@loveyeguo
Copy link

 private async Task KeepAccept(Socket listenSocket)
 {
     while (!_cancellationTokenSource.IsCancellationRequested)
     {
         try
         {
             var client = await listenSocket.AcceptAsync().ConfigureAwait(false);
             OnNewClientAccept(client);
         }
         catch (Exception e)
         {
             if (e is ObjectDisposedException || e is NullReferenceException)
                 break;
             
             if (e is SocketException se)
             {
                 var errorCode = se.ErrorCode;

                 //The listen socket was closed
                 if (errorCode == 125 || errorCode == 89 || errorCode == 995 || errorCode == 10004 || errorCode == 10038)
                 {
                     break;
                 }
             }
             
             _logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync");
             continue;
         }
     }

     _stopTaskCompletionSource.TrySetResult(true);
 }

在这段代码中,
var client = await listenSocket.AcceptAsync().ConfigureAwait(false);
目前大约有几百个tcp客户端在像我tcp服务端发送报文。
日志一直在报:远程主机强迫关闭现有连接,推测是有不合法的客户端一直在断掉重连,在运行几个小时以后,tcp服务端程序无法再接收新的连接。

@loveyeguo
Copy link
Author

是否在代码
_logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync");后面,应主动调用:
client?.Close();

@loveyeguo
Copy link
Author

重启后又恢复正常,但是过几个小时,客户端又开始无法再次建立新连接。

@kerryjiang
Copy link
Owner

_logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync"); 这个记录的什么?你拿到了没有?

@loveyeguo
Copy link
Author

以下是报错的详细内容: 然后几个小时后,后续客户端已经无法再建立新连接

[2024-12-13 15:56:30.184028 +08:00]-[fail]: TcpChannelCreator[0]-[threed:6]
     Connection reset by remote client: ****************************异常文本****************************
     【出现时间】:2024/12/13 15:56:30
     【异常类型】:SocketException
     【异常信息】:远程主机强迫关闭了一个现有的连接。
     【堆栈调用】:   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.Socket>.GetResult(Int16 token)
        at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
     --- End of stack trace from previous location ---
        at SuperSocket.Server.TcpChannelCreator.KeepAccept(Socket listenSocket) in D:\coding\夏工\code\SuperSocket-master\src\SuperSocket.Server\TcpChannelCreator.cs:line 103
     ***************************************************************

[2024-12-13 15:56:30.185471 +08:00]-[fail]: TcpChannelCreator[0]-[threed:6]
     Connection reset by remote client with IP: 220.248.164.71
[2024-12-13 15:56:40.311129 +08:00]-[fail]: TcpChannelCreator[0]-[threed:13]
     Connection reset by remote client: ****************************异常文本****************************
     【出现时间】:2024/12/13 15:56:40
     【异常类型】:SocketException
     【异常信息】:远程主机强迫关闭了一个现有的连接。
     【堆栈调用】:   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.Socket>.GetResult(Int16 token)
        at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
     --- End of stack trace from previous location ---
        at SuperSocket.Server.TcpChannelCreator.KeepAccept(Socket listenSocket) in D:\coding\夏工\code\SuperSocket-master\src\SuperSocket.Server\TcpChannelCreator.cs:line 103

@loveyeguo
Copy link
Author

我再完整的描述一下: 如上,我部署了tcp服务端,目前大约有200多个tcp客户端连接。 我同时侦听了1799,1800端口。 经测试,如上错误一直在报,大概一分钟左右报一次。 持续几个小时后,1799端口已无法再次连接。但是1800端口(此端口为测试端口,目前只有几个tcp客户端连接)是正常可以连接的。 请问出现的原因是什么? 猜测是否有资源未正确释放?

@loveyeguo
Copy link
Author

请注意,我替换成原来的SuperSocket1.6老版本后,未发现任何报错信息。也没有出现后续客户端无法连接的情况!

@loveyeguo
Copy link
Author

_logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync"); 这个记录的什么?你拿到了没有?

在线等啊大佬!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants