How to find the reason and SocketException with a message that the established connection was interrupted by software on your main machine?

I know that a similar question could be asked many times, but I want to present the behavior that I see and find out if anyone can help predict the reason for this.

I am writing a Windows service that connects to another Windows service through TCP. In total there are 100 user objects and 5 connections for each. These users complete their tasks using their individual connections.

The application continues to see this problem for 1 or 2 days. Or sometimes show the problem immediately after starting (-rarely). The best run I had was like 4-5 days without showing this exception. And after that, the application died, or I had to stop it for various reasons.

I want to know what could be causing this? Here is the stacktrace.

System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Security._SslStream.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security._SslStream.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)

+4
source share
1 answer

Did you find a solution? Perhaps you can get closer to the solution if you add network tracing to your app.config?

 <?xml version="1.0"?> <configuration> <system.diagnostics> <sources> <source name="System.Net.Sockets"> <listeners> <add name="Sockets"/> </listeners> </source> </sources> <switches> <add name="System.Net.Sockets" value="31"/> </switches> <sharedListeners> <add name="Sockets" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\socketdump.log"/> </sharedListeners> <trace autoflush="true"/> </system.diagnostics> </configuration> 

Alternatively, you can configure logging for TLS / SSL. Add the following DWORD and set it to 7, in the registry, reboot and view all schannel events in the system event log:

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\EventLogging 

Hope this helps, but there may be many bumps in the dark, I think ...

+3
source

Source: https://habr.com/ru/post/1301772/


All Articles