Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An established connection was aborted by the software in your host machine

Tags:

c#

Sorry if this is a bit long winded but I thought better to post more than less.

This is also my First post here, so please forgive.

I have been trying to figure this one out for some time. and to no avail, hoping there is a genius out there who has encountered this before.

This is an intermittent problem and has been hard to reproduce. The code that I am running simply calls a web service The Web Service call is in a loop (so we could be doing this a lot, 1500 times or more)

Here is the code that is causing the error:

HttpWebRequest groupRequest = null;
WebResponse groupResponse = null;            
try
{    
    XmlDocument doc = new XmlDocument();
    groupRequest = (HttpWebRequest)HttpWebRequest.Create(String.Format(Server.HtmlDecode(Util.GetConfigValue("ImpersonatedSearch.GroupLookupUrl")),userIntranetID));
    groupRequest.Proxy = null;
    groupRequest.KeepAlive = false;
    groupResponse = groupRequest.GetResponse();
    doc.Load(groupResponse.GetResponseStream());
    foreach (XmlElement nameElement in doc.GetElementsByTagName(XML_GROUP_NAME))
    {
         foreach (string domain in _groupDomains )
         {
             try
             {
                 string group = new System.Security.Principal.NTAccount(domain, nameElement.InnerText).Translate(typeof(System.Security.Principal.SecurityIdentifier)).Value;
                 impersonationChain.Append(";").Append(group);                            
                 break;
             }
             catch{}                        
         } // loop through            
     }
 }
 catch (Exception groupLookupException)
 {
     throw new ApplicationException(String.Format(@"Impersonated Search ERROR:  Could not find groups for user<{0}\{1}>", userNTDomain, userIntranetID), groupLookupException);
 }
 finally
 {
     if ( groupResponse != null )
     {
         groupResponse.Close();
     }
 }

Here is the error that happens sometimes:

Could not find groups for user<DOMAIN\auser> ---> System.IO.IOException: Unable to read
data from the transport connection: An established connection was aborted by the
software in your host machine. ---> System.Net.Sockets.SocketException: An established  
connection was aborted by the software in your host machine at  
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags  
socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32  
size) --- End of inner exception stack trace --- at System.Net.ConnectStream.Read(Byte[]  
buffer, Int32 offset, Int32 size) at System.Xml.XmlTextReaderImpl.ReadData() at  
System.Xml.XmlTextReaderImpl.ParseDocumentContent() at  
System.Xml.XmlLoader.LoadDocSequence  
(XmlDocument parentDoc) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.Load(Stream inStream) at  
MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters,  
String userIntranetID, String userNTDomain)--- End of inner exception stack trace  
---at MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters, String userIntranetID, String userNTDomain)  
--- End of inner exception stack trace ---  
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message,  
WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,  
Object[] parameters) at MyProgram. MyWebServices.ImpersonatedSearch.PerformQuery  
(QueryParameters parameters, String userIntranetID, String userNTDomain)  
at MyProgram.MyMethod()

Sorry that was alot of code to read through.
This happens about 30 times out of around 1700

like image 553
TheCodeFool Avatar asked Oct 22 '09 16:10

TheCodeFool


1 Answers

You're probably hitting a timeout. First of all, turn the keepalive back on. Second, check the timestamps on the request and reply. If there is a firewall between the sender and receiver, make sure that it isn't closing the connection because of idle timeout. I've had both these problems in the past, although with generic socket programming, not DB stuff.

like image 95
jfawcett Avatar answered Sep 21 '22 07:09

jfawcett