A lesson learned about concurrent calls and WCF binding config.

I learned yet another binding configuration attribute today, that plays a rather important role if you have a service that could accept a large amount of concurrent calls.  By concurrent, I mean dozens of calls that come in at the same time.   Of course the standard throttles in this scenario are important, maxConnections on the binding and the various service model throttles (maxConcurrentCalls,maxConcurrentSessions,maxConcurrentInstances).  There is however one attribute that you may not be aware of, that if not set correctly will cause your clients to throw a rather nondescript exception like:

"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.4383964'."

After spending the better part of a day, changing settings and staring at trace logs, I posted in the MSDN forums an example application demonstrating this behavior.  In the end, the solution to the exception was setting the listenBacklog attribute on the binding.  What does it do?  (from MSDN) "ListenBacklog is a socket-level property that describes the number of "pending accept" requests to be queued. Ensure that the underlying socket queue is not exceeded by the maximum number of concurrent connections."  So, ensure that you have this set higher or equal to the amount of maxConcurrentCalls.

Hope that helps someone else staring at a trace log, that doesn't indicate there are any problems with the service config.   Hopefully at some point a more descriptive exception is thrown when you hit this binding throttle.
 

 

2 Comments

  • Hey Jason, I get the exact same error with an inner exception with following message "
    An existing connection was forcibly closed by the remote host".
    My WCF is a Windows Service but I can't connect to it. The same code works fine in a ConsoleApp server.
    Please advise.
    Regards

  • why do you not make the change in the service config?

Comments have been disabled for this content.