WCF client "Insufficient winsock resources" error after about 2 hours

System Description: I have a WCF service (hosted on a Windows service itself) that is consumed by a client (also a Windows service). These two applications are designed for continuous uptime. The queue application reads records from the database, sends jobs to the WCF service for processing, which returns some information to the client, and the client saves the results back to the database.

Error Details: After about two hours, the client application can no longer connect to the WCF service reporting the error:

"There are not enough winsock resources available to complete socket initialization." ,

The second application, which runs on the same server, also starts throwing exceptions from now on:

"A network-related or specific instance error occurred while establishing a connection to SQL Server. The server was not found or is unavailable. Verify the instance name is correct and configure SQL Server to allow remote connections. (Provider: named pipe provider, error: 40 - connection could not be opened with SQL Server) "

The second application has nothing to do with the WCF client and server, it just runs on the same server and just reads / writes to the database.

Setup / server / client code:

Server Details:

  • Self-hosted inside a Windows service.
  • NetTcpBinding
  • ReceiveTimeout = "00:00:15"
  • serviceThrottling maxConcurrentCalls = "2147483647"
  • maxConcurrentSessions = "2147483647"

Client Connection Class ::

public class ClientConnectionClass : ClientBase<IFileService>, IFileService, IDisposable { public void callMethod(InputRequest request) { result = base.Channel.doRequest(request); } void Dispose() { bool success = false; try { if (State != CommunicationState.Faulted) { Close(); success = true; } } finally { if (!success) { Abort(); } } } } 

Client process (Windows service):

 while(true) { // Do some stuff before, code ommited ClientConnectionClass ccc = new ClientConnectionClass(); ccc.callMethod(inputRequest); // Do some stuff with the response // Close the connection class, is this the right way to close it? ccc.Close(); Thread.Sleep(1000); } 

Possible explanations: I think that based on the first exception error, the code does not close / release socket connections or start ports for connections (note that I explicitly call the Close () method of ClientBase from ClientProcess, in addition to the implementation of the Dispose () method in ClientBase).

Notes: The client application is multi-threaded, up to 4 simultaneous threads are running simultaneously, each of which calls the WCF service. The client for the WCF service runs fully up to the 2-hour (ish) point where the Client process spits out errors, and other (unrelated) Windows services (which use network resources) also start to spit out errors.

Possible questions to answer: Am I creating / managing a class that implements the ClientBase class? Is there an easier way to debug / register the current status of the client service or WCF (I attached the perfmon.exe file, but in fact it does not provide much useful information about sockets / networks).

thanks

UPDATE: I actually wrapped the ClientConnectionClass in a 'using' statement, I'm currently testing this (it usually takes 2 hours). Refresh , this did not work.

+4
source share
2 answers

What platform are you working on? Win2k3, Win2k8? I saw unreasonable messages about web applications experiencing similar problems running on pre-Win2k8 systems that "allow" work on Win2k8. In addition, if the client and server are running on the same system, is it possible to use namedpipe vs. binding nettcp? Not quite a fix, but may solve your problem.

0
source

I work in a very similar situation using Windows Server 2008 R2 SP1. For some time, problems and studies were fixed. Found a support article that sounds exactly the same.

This may be for you:

http://support.microsoft.com/kb/2577795

There is a fix.

The symptom described in the article:

“Consider the following scenario: You have a multiprocessor computer running Windows Server 2008 R2 or Windows 7. You run an application that creates loopback loops on the computer. In this case, the application may be unable to create new sockets, and an exception will occur on the computer without buffer space "In addition, if this problem occurs, users cannot remotely connect to the computer until it restarts."

The reason described in the article:

"This problem occurs because of the race condition in the helper function driver for WinSock (Afd.sys), which causes a socket leak. Over time, the problem described in the" Problem "section occurs if all available sockets have run out of resources."

UPDATE. I checked the update of one server, and not another, which fix fixes the problem. Send them side by side, and one without a fix has encountered a WinSock problem, while the patched server is still updating its source ports in the 49-50k range.

+4
source

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


All Articles