none
Suddenly HttpWebRequest times out RRS feed

  • Question

  • I have been using System.Net.HttpWebRequest (in PowerShell scripts) without trouble with jobs running daily for almost a decade.  Suddenly yesterday, majority of the requests timed out.  The observations collected are:

    1. The same problem appeared on the same day on three different PCs in three different locations (but accessing the same web site).
    2. Using IE or Chrome, the web site loads fast and fine at all three PCs.
    3. By turning on Fiddler, ie the HttpWebRequest now goes via Fiddler, they work fast and fine, on the same web site.  It is consistent and reproducible. I turned on Fiddler, the requests completed immediately, I turned off Fiddler, most of the requests timed out.
    4. All the requests are made with User-Agent taking on a typical real world IE or Chrome.  Anyway, going through the Fiddler proxy works fine means it is unlikely the web server is playing tricks based on UA.
    5. About the first ten HttpWepRequests each time a script is run work fine.  The problem start after the 10th request.

    What can be the possible cause?  Thanks.

    • Edited by K.Kong Thursday, July 23, 2015 1:03 AM
    Friday, July 17, 2015 8:05 AM

Answers

  • Hello K.Kong,

    >> What can be the possible cause?  Thanks.

    Since we are unable to reproduce this scenario you mentioned, here are some suggestions could help diagnose this issue, please try:

    1.Make sure what timeout it is, since as we know there are two kinds timeout:http://blogs.msdn.com/b/buckh/archive/2005/02/01/365127.aspx?Redirected=true

    2.Make sure if it could be a server side timeout, please try to set

    request.Timeout = Timeout.Infinite;
    
    request.KeepAlive = true;

    to check if it would get the correct response.

    3. You can also look at WebException.Status. The WebExceptionStatus enum has a Timeout flag:

    try
    
    {
    
       using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    
       {
    
          WebHeaderCollection headers = response.Headers;    
    
          using (Stream Answer = response.GetResponseStream())
    
          {
    
              // Do stuff
    
          }
    
       }
    
    }
    
    catch (WebException e)
    
    {
    
       if (e.Status == WebExceptionStatus.Timeout)
    
       {
    
          // Handle timeout exception
    
       }
    
    }

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, July 20, 2015 3:29 AM
    Moderator