views:

1109

answers:

4

Hi,

I have a multi-thread application (in c#) that it does multiples HTTP GET to uri. Suddenly after of thousand of requests, i get timeout webException but destination server is OK if i test using browser. The code is:

public static string Get(string uri)
{
    string responseData = string.Empty;
    using (WebClient wc = new WebClient())
    {
        responseData = wc.DownloadString(uri);
    }
    return responseData;
}

I think it is dispose connection issue or similar error. Any body has same problem?

Thx in advance,

PS I have used HttpWebResponse too. But i get same error.

PS OS is Windows 2003 server. So i think is not connection limits.

I have try with this code too and i get same error

  public static string Get2(string uri)
 {
  string responseData = string.Empty;          
  WebRequest request = WebRequest.Create(uri) as HttpWebRequest;
  request.Method = "GET";
  request.Timeout = 35000; 
  using(HttpWebResponse response = (HttpWebResponse)request.GetResponse() as HttpWebResponse)
  {     
   using(Stream dataStream = response.GetResponseStream ())
   {     
    using(StreamReader reader = new StreamReader (dataStream))
    {
     responseData = reader.ReadToEnd();      
    }
   }
  }   
  return responseData;
 }
A: 

Quick question(s)

  1. Is the server also your code?
  2. How many are multiple requests?
  3. Try ping -t on your server and see if any packet loss is reported from your client machine.

Have you thought of maybe the server exhausts all its resources handling your requests and just plain and simple restarts itself. Thats why you get a timeout when you are doing a query but by the time you do the browser ping, it is back up. Just a thought

Since, you mention "thousands of requests", I am more inclined to think a resource crunch on the server rather than a connectivity issue.

Aditya Sehgal
1) There are two different server. Mine for request and destination is always running.2) I get the error from 12K request.Yes i think it is a connection dispose problem, but i use using {}. If i restart application, then all is ok until reach 10K request.
fravelgue
do you have access to server logs? Having a "connection problem" after about 10K problem does not *sound* right to me. It looks to me like a resource crunch. Can you try running wireshark with http filter at the time you are experiencing these timeouts
Aditya Sehgal
A: 

This could be caused by any number of reasons including:

  • Brief transient loss of connectivity between your application and the remote web server

  • The remote server is possibly not responding in time due to load

I suggest setting a longer timeout on the request but you'd need to use WebRequest instead because there is no way to set a timeout on WebClient.

Kev
I think those are not problem. Because i can Get using browser while i get the error (exist a retry function). Timeout throw at 00:01:40. I have try using HttpWebResponse with high Timeout too and i get same error.
fravelgue
A: 

Having faced this myself what I found to work is to try your get request a few more times after a short Wait() on that thread for say 5 seconds and if it doesn't work it is best to leave the server alone for some time. :-)

Gaurav
+1  A: 

Some links with same problem.

fravelgue