6

I am using a service to pull in a list of hotels in the form of an XML document. All of this works fine on our dev server when testing it, however shorty after deploying it live all the pages using this are broken and are displaying this error:

An operation on a socket could not be performed because the system lacked
sufficient buffer space or because a queue was full 91.103.175.187:80

Description: An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error
and where it originated in the code. 

Exception Details: System.Net.Sockets.SocketException: An operation on a socket
could not be performed because the system lacked sufficient buffer space or
because a queue was full 91.103.175.187:80

Stack Trace: 

[SocketException (0x2747): An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full 91.103.175.187:80]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +305
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +699

[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetResponse() +7859156
Laterooms.Gateway.LateroomsGateway.GetHotelsWithurl(String url)
Laterooms.Gateway.LateroomsGateway.GetHotelsByKeyword(String keyword, String orderBy) 
Laterooms.LateroomsManager.GetHotelsByKeyword(String keyword, String orderBy, String lang)

After seeing this I thought it maybe due to the amount of requests being made so I implemented caching but still the same issues are occurring. Here is the code I am using to pull in the data:

    HttpWebRequest request = null;

    Uri uri = new Uri(url);
    request = (HttpWebRequest)WebRequest.Create(uri);
    request.Method = "POST";
    request.AllowWriteStreamBuffering = false;
    request.ContentLength = 0;
    request.KeepAlive = false;

    using (WebResponse response = request.GetResponse())
    {
        using (Stream dataStream = response.GetResponseStream())
        {
            _LateroomsXml.Load(dataStream);
        }
    }

Again this issue only occurs on on our live server. After many hours of debugging and googling I have not come any closer to solving this issue.

Any help on this would be greatly appreciated!

shoughton123
  • 4,255
  • 3
  • 21
  • 23
  • 1
    what virtual memory is assigned to the live box - I had a very similar issue once caused by insufficient virtual mem even though the server itself had plenty of standard memory – Johnv2020 Jun 18 '13 at 11:49
  • It's got 4gb assigned to it at the moment it's only running at 2gb. I thought this might be the issue as well but it doesn't seem to be. – shoughton123 Jun 18 '13 at 12:07
  • Possible duplicate of ["An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full"](http://stackoverflow.com/questions/4415175/an-operation-on-a-socket-could-not-be-performed-because-the-system-lacked-suffi) – Ash Mar 30 '17 at 22:53

2 Answers2

12

Please don't use that fix. Your problem is you have keep alives disabled, so it's using a different connection for every request, and a port which is then unable to be used again for a couple of minutes. It's doing exactly what it's supposed to be doing.

Enable keep-alive and your problem will go away.

user1495282
  • 231
  • 4
  • 7
2

I found the fix for this in end just in case anyone else is stuck!

From here

https://support.microsoft.com/en-us/kb/196271

  1. Start Registry Editor.

  2. Locate the following subkey in the registry, and then click Parameters: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

  3. On the Edit menu, click New, and then add the following registry entry:

    Value Name: MaxUserPort

    Value Type: DWORD

    Value data: 65534

    Valid Range: 5000-65534 (decimal)

    Default: 0x1388 (5000 decimal)

  4. Exit Registry Editor, and then restart the computer.

This combined with some better caching so the data isn't being pulled in every time a user loads the page will prevent this from happening again.

installero
  • 9,096
  • 3
  • 39
  • 43
shoughton123
  • 4,255
  • 3
  • 21
  • 23
  • can you explain what does this exactly do ? – JohnTube Feb 01 '15 at 00:16
  • You can find a complete answer in this [link](http://www.outsystems.com/forums/discussion/6956/how-to-tune-the-tcp-ip-stack-for-high-volume-of-web-requests/). – flaviussn May 15 '15 at 12:15
  • 2
    this is not an solution, it is a hack, it will just postpone the problem until you face higher load – mfarouk Jul 17 '17 at 23:29