title: The I/O operation has been aborted because of either a thread exit or an application request in WCF
body: <p>I have already seen following questions and their non-working answers.</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/15013307/no-matter-what-i-try-the-i-o-operation-has-been-aborted-because-of-either-a-thr">No matter what I try: The I/O operation has been aborted because of either a thread exit or an application request</a></li>
  <li><a href="https://stackoverflow.com/questions/7228703/the-i-o-operation-has-been-aborted-because-of-either-a-thread-exit-or-an-applica">The I/O operation has been aborted because of either a thread exit or an application request</a></li>
  <li><a href="https://stackoverflow.com/questions/7339683/the-i-o-operation-has-been-aborted-because-of-either-a-thread-exit-or-an-applica">The I/O operation has been aborted because of either a thread exit or an application request</a></li>
  </ol>
  
  <p>I have a console application with which I am stress testing my WCF service. When I make more than 80 simultaneous calls to the service, sometimes it works all fine and sometimes some of the calls fail with following exception.</p>
  
  <p><strong>Exception Type:</strong> System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</p>
  
  <p><strong>Message:</strong> The I/O operation has been aborted because of either a thread exit or an application request</p>
  
  <p><strong>StackTrace:</strong></p>
  
  <p>at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()</p>
  
  <p>at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)</p>
  
  <p>at System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender, SocketAsyncEventArgs e)</p>
  
  <p>at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)</p>
  
  <p>at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)</p>
  
  <p>at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)</p>
  
  <p>at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)</p>
  
  <p>I am calling following code using loops :</p>
  
  <pre><code>var tcpb = new NetTcpBinding();
  TimeSpan timeOutAfter =  new TimeSpan(0, 10,0);
  tcpb.OpenTimeout = timeOutAfter;
  tcpb.SendTimeout = timeOutAfter;
  tcpb.CloseTimeout = timeOutAfter;
  tcpb.Security.Mode = SecurityMode.None;
  
  string address = "net.tcp://" + MYIP + ":" + PORTNUMBER + "/" + PORTTYPE + "/";
  
  ChannelFactory&lt;ServiceName&gt; channelFactory = new ChannelFactory&lt;ServiceName&gt;(tcpb,address);
  var client = channelFactory.CreateChannel();
  ((IClientChannel)client).Open();
  //Function Call here
  ((IClientChannel)client).Close();
  channelFactory.Close();
  </code></pre>
  
  <p>Any ideas ans solutions are greatly appreciated.</p>