kerryjiang / SuperSocket

SuperSocket is a light weight, cross platform and extensible socket server application framework.
Apache License 2.0
3.91k stars 1.15k forks source link

Connection reset by peer #638

Open kinguru opened 1 year ago

kinguru commented 1 year ago

Dear Kerry,

Could you please describe what does mean "Connection reset by peer" exception? I've a lot of such messages but from few IPs only. I'm using the latest beta15 version but seems it's not related to version.

The client reconnect every second with +1 remote port number. Is it related to customer side network issue or something I should worry about?

Full stack trace:

Failed to create channel for 220.180.239.155:64567.System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException (104): Connection reset by peer --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token) at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request) at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at SuperSocket.Server.TcpChannelCreatorFactory.<>c__DisplayClass3_0`1.<b__1>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at SuperSocket.Server.TcpChannelCreator.OnNewClientAccept(Socket socket)

chucklu commented 1 year ago

It's a network issue, none business of this library, please check What does "connection reset by peer" mean?

Answer from ChatGPT The error message "Unable to read data from the transport connection: Connection reset by peer" is a network-related error that occurs when a network connection is unexpectedly closed by the remote host. This can happen for several reasons, including:

The remote server has closed the connection due to an internal error or timeout.
There is a network interruption or problem that is causing the connection to be reset.
The client or server has terminated the connection.

To troubleshoot this issue, you can try the following steps:

Check the network connection and ensure that it is stable and has sufficient bandwidth.
Check if the remote server is under heavy load or experiencing issues that may cause it to terminate connections.
Ensure that the client and server are using compatible protocols and configurations.
Check if there are any firewalls or proxies that may be interfering with the connection.
Increase the timeout value on the client side to allow more time for the connection to be established.
If the issue persists, try using a different client or server to isolate the problem.
kinguru commented 1 year ago

Thank you. Is there a way to catch this kind of exception in the my code? Currently it's just logged to the log file and I have no idea where does it happen to handle it correctly (may be log more information or ban IP addresses).

chucklu commented 1 year ago

From the stack trace you provided, you might try to catch the exception SuperSocket.Server.TcpChannelCreator.OnNewClientAccept(Socket socket)

There is nothing you can do on code level, just check the above potential problems, none of them can be handled on code level. For current case, is your server crash? If it's not crash, then let it be. Record log is enough.

kinguru commented 1 year ago

No server crash.

I'd version 2.0.0-alpha before and today I have installed recent beta15. After upgrade I've 50 times more exceptions "Failed to create channel for ... reset by peer". On old version I had ~100 such exception in time interval. After update ~5000 in same interval.

Could it be due TLS version or something else? Don't understand does customers has connection issues or just another kind of logging in the new supersocket library used.

kinguru commented 1 year ago

such exceptions rate

image
kerryjiang commented 1 year ago

Thats strange. Beta 15 has nothing code change. The only change is adding more target frameworks.

kinguru commented 1 year ago

previous used was not beta 14, it was 2.0.0-preview3-05

kerryjiang commented 1 year ago

It looks like the connection dropped when the server was accepting it. Probably the preview version suppressed this error.

kinguru commented 1 year ago

It would be good to have ability to log some additional information at this step. Is it possible?

kerryjiang commented 1 year ago

At that moment, you have no way to access http header because the connection was not accepted.