-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
"Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host." #764
Comments
Did you use the same client test code for other TCP server implementation? I noticed it might be the problem of your client test code. CancellationToken should not be passed to the methods SendAsync/FlushAsync and ReceiveAsync. Because the token is triggered by timer when send/receive is happening. An task cancelled exception will be thrown in that case and the connection will drop from client side. I also got failures in this unit test when I pass in cancellation token but it works fine after I stopped passing the cancellation token. |
The same client test code is tested for other TCP server implementation and works as expected. The CancellationToken is triggered only when the DurationMinutes is expired as shown below.
The test code cancels the token after 1 minute, but the exception is thrown before [2024-12-09T13:15:02.5121029+05:30]:Starting test... Added a few Console.Writeline to the test code to print the test start, cancel, and complete time.
Also, this failure is sporadic. |
But I cannot reproduce this issue with this unit test: SuperSocket/test/SuperSocket.Tests/PerfTest.cs Lines 22 to 58 in 934acd7
|
SuperSocket/test/SuperSocket.Tests/PerfTest.cs In a production environment, we won't have any control over how the client application initiates a connection to the server. As a server, the expected behavior is, that both Socket-based or TcpClient-based clients should be able to connect to the server. There is one more observation, the failure is noticed when using the asynchronous connect API of TcpClient |
I have also observed the same behavior when I use TcpClient connected to server written using Supersocket |
Ok, let me test with TcpClient. |
The source code of TcpClient.ConnectAsync: |
Do you see any issue with implementation ?, I couldn't find any issues. |
Description
When concurrent TCP clients try to connect to the super socket server, a few connections fail with the error "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host."
I have a concurrency test(MsTest)
in which 10 TCP clients connect to the supersocket server and continue sending data for 1 minute.
While running this test, I always see a few connections are closed and unable to write to the stream. However, there is no error logged in the server console.
Also for every new connection superscoket logs the message "A new session connected..." as shown below.
info: SuperSocketService[0]
A new session connected: 63ec0218-7af5-4ea4-95e2-41adcf571004
In this scenario, the new sessions connected are less than 10 connections.
Code Sample
--Csharp
SuperSockerDemo.zip contains the sample code to reproduce the issue.
UnitTest1 - It has the concurrency test which creates 10 TCP clients and connects to the server.
Once the connection is established it keeps sending data to the server for 1 minute
Program.cs has code to host the server and SupersocketRequestProcessor.cs processes the message.
The same test works as expected with other TCP server implemented without super socket.
SuperSockerDemo.zip
.NET Version
.NET 8.0
Additional Information
The text was updated successfully, but these errors were encountered: