简体   繁体   中英

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

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM