Hi @David Drápela,
I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.
Issue:
Customer has migrated a service that was previously running on-premise to Azure where the app is based on .NET and containerized in Docker. It is just a single container with no scaling, they have deployed the container to ACI and the app includes two TCP listeners using custom, non-HTTP protocols. If they create a TCP connection to the service via any of the 2 ports the connection gets periodically interrupted every few minutes and the connection gets seemingly interrupted at random intervals and if there are multiple connections to the service they get interrupted at the same time.
The error on the server side:
Unable to read data from the transport connection: Connection timed out.: at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
The error on the client side:
Unable to read data from the transport connection: An existing connection was forcibly closed ( v System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult) at System.Net.Security.SslStream.EndRead(IAsyncResult asyncResult)
The TCP listener in the example uses SSlStream, but the listener on the second port uses insecure TcpListener and it's the same problem.
Solution:
OP performed migration from ACI containers to ACA and verified its now working properly.
If you have any other questions or are still running into more issues, please let me know.
Thank you again for your time and patience throughout this issue.
Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.