intermittent timeout problem when using Request.GetResponse()

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a web application which uses multiple threads to connect to a couple
of other web servers. All works very well, except occasionally when the load
is a bit heavy, I start getting errors on my connect method. I don't believe
the error is coming from the servers I connect to, since I have gotten the
errors from both servers at different times, and both are not related to each
other in any way (different vendors). I always retry my request a few
seconds later, and all works fine the 2nd or 3rd time around.

I've worked on this problem for months now, it's driving me nuts! Any help
would be so greatly appreciated.

The errors I get vary, but it's always one of the following:
- The operation has timed-out
- The underlying connection was closed: The request was canceled
- (occasionnally, but not often) Object reference not set to an instance of
an object
- Non-negative number required. Parameter name: byteCount

Looking up on various newsgroups, I find many others who experience the same
issues (ie: http://www.dotnet247.com/247reference/msgs/30/152007.aspx)
Unfortunately, I haven't found a resoltuion as of yet. Microsoft KB
mentions something about it, but I guess I'd have to pay for the support...
(http://support.microsoft.com/default.aspx?scid=kb;en-us;819450)

I have attached my connect method below (in C#). Thanks again for any help!

private HttpWebResponse connect(string url, string variables)
{
StreamWriter myWriter = null;
HttpWebRequest objRequest = null;
HttpWebResponse response = null;

try
{
objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = variables.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
objRequest.KeepAlive = false;
objRequest.Proxy = GlobalProxySelection.GetEmptyWebProxy();
objRequest.Timeout = VOLT_TIMEOUT_MILLISECONDS;

myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(variables);
myWriter.Close();

response = (HttpWebResponse)objRequest.GetResponse();
}
catch (ThreadAbortException)
{
if (response != null)
response.Close();
Thread.ResetAbort();
}
catch (Exception ex)
{
if (response != null)
response.Close();

throw new Exception("Exception occurred in VoltDelta.connect(" + url + ",
" + variables + "): " + ex.Message);
}
return response;
}
 
Are you sure you are closing the response object correctly ? Sometimes a
timeout is indicative of the fact that the response object wasnt closed. Are
you sure that when you return the response object in the success case, that
the caller closes the response object ?

In the case when you get request cancelled, you just need to reissue the
request.

I dont know where the argument exception is coming from. A stack trace might
help

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
 
Did you find a solution to the problem?

Feroze said:
Are you sure you are closing the response object correctly ? Sometimes a
timeout is indicative of the fact that the response object wasnt closed. Are
you sure that when you return the response object in the success case, that
the caller closes the response object ?

In the case when you get request cancelled, you just need to reissue the
request.

I dont know where the argument exception is coming from. A stack trace might
help

--
feroze

-----------------
This posting is provided as-is. It offers no warranties and assigns no
rights.

See http://weblogs.asp.net/feroze_daud for System.Net related posts.
----------------
 
Back
Top