4

I have already seen following questions and their non-working answers.

  1. No matter what I try: The I/O operation has been aborted because of either a thread exit or an application request
  2. The I/O operation has been aborted because of either a thread exit or an application request
  3. The I/O operation has been aborted because of either a thread exit or an application request

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.

Exception Type: System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Message: The I/O operation has been aborted because of either a thread exit or an application request

StackTrace:

at System.ServiceModel.Channels.SocketConnection.HandleReceiveAsyncCompleted()

at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)

at System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender, SocketAsyncEventArgs e)

at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)

at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)

at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)

at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

I am calling following code using loops :

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<ServiceName> channelFactory = new ChannelFactory<ServiceName>(tcpb,address);
var client = channelFactory.CreateChannel();
((IClientChannel)client).Open();
//Function Call here
((IClientChannel)client).Close();
channelFactory.Close();

Any ideas ans solutions are greatly appreciated.

Community
  • 1
  • 1
ninja
  • 45
  • 1
  • 1
  • 5
  • you should post code if you want peoples help.... Show how you are testing the service. – T McKeown Jan 26 '14 at 06:02
  • @TMcKeown I have added my calling code in my question. – ninja Jan 26 '14 at 06:14
  • are you sure you are waiting long enough after the call? If you execute many concurrent calls then I would guess you could get some lag in response. Aren't you possibly shutting down the socket too early? – T McKeown Jan 26 '14 at 06:18
  • All my timouts are 10minutes. I am not getting any timeouts in traces. – ninja Jan 26 '14 at 06:20
  • ok but I see you calling .Close()... when is that being called? Immediately? As you can see in the stack trace, the error occurs while waiting for a response. – T McKeown Jan 26 '14 at 06:21
  • "All my timeouts" => including on the server? Last time I had this problem someone had changed `receiveTimeout` from 5 minutes to 5 seconds. I've also had this problem due to certificate revocation checks taking too long (externally accessing a resource with a self signed cert but the cert had a revocation server whose address was internal). *When I make more than 80 simultaneous calls to the service* Also keep an eye out for service throttling and the listen backlog. – ta.speot.is Jan 26 '14 at 06:22
  • @ta.speot.is Yes both service side and the clientside all timeouts are 1o minutes. – ninja Jan 26 '14 at 06:23
  • @ta.speot.is I have put throttle of 1000 concurrent calls. – ninja Jan 26 '14 at 06:24
  • @TMcKeown My function call goes to database and it just returns 3 rows. I am calling close after this data is retrieved and returned. – ninja Jan 26 '14 at 06:26
  • ok, but why does the stack trace refer to AsyncComplete? Sync calls wouldn't throw that. – T McKeown Jan 26 '14 at 06:27
  • ^^^I'm guessing on that... i just don't recall seeing Async unless I'm doing Async – T McKeown Jan 26 '14 at 06:29
  • @TMcKeown I assume this is for handling calls in async way. I have used `InstanceContextMode = InstanceContextMode.PerCall` on my service code – ninja Jan 26 '14 at 06:29
  • It's not uncommon to implement synchronous calls with their asynchronous counterparts ... as long as you know what you're doing, it beats writing the same function twice. It's not like synchronous calls can't use asynchrony -- they just have to be synchronous. How they do that => implementation detail. – ta.speot.is Jan 26 '14 at 06:29

1 Answers1

1

My guess is your service can't cope with the 80 concurrent calls.

Look at WCF Throttling to configure the maximum number of concurrent calls your service should support. There is a good topic on Code Project about this.

Also the default InstanceContextMode of TCP bindings is PerSession and default behavior of WCF is to allow maximum 16 concurrent sessions. If session mode is not required, you should configure the service to use InstanceContextMode.PerCall. This is far more scalable than PerSession...

Marc Selis
  • 833
  • 12
  • 17