0

I have a client application (.NET framework 4.6) calling an API (.NET framework 4.7) to get data inside Azure Cosmos DB that matches certain condition and return the count of these data.

For smaller databases, calls return results just fine. However, when it calls larger and/or more databases at once, the call terminates at around 100~110 seconds with System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host error. The duration of call is pretty consistent, so I am leaning towards some default timeout value I am not aware of.

Looking at the logs, this exception is only observed from the client side, and the remote host (API) side does not have any exceptions related to this operation. In addition, when called multiple databases at once, smaller databases returned 200, but there is no response recorded from larger databases. I believe it terminates when socket exception is thrown from API.

So far, I have tried implementing ServicePoint.SetTcpKeepAlive option on both client and API, as well as extending the HttpClient's timeout from the client application, but nothing seems to work.

I also went over the thread An existing connection was forcibly closed by the remote host, but most of the suggestions don't match my situation.

The fact that this code works for smaller databases makes me think it has to do with database size + wait time due to is volume, or timeout value for connection, but I can't seem to find what this could be.

Thank you in advance for your suggestions or comments to solve this issue.

ctech
  • 1
  • Well client requests only work well if the network works well too. You never know how many firewalls, load balancers, proxies...etc. your client request has to pass until it reaches the destination. Many network load balancers or firewalls close client connection requests if the number of active connections reaches a certain limit. I have seen this error alot in my own services, the reason was almost always network bandwidth limitations. I suggest to get in contact with the network engineers and to retry your failed requests – Siraf Oct 07 '22 at 08:55

0 Answers0