Roman Puttkammer
2003-08-07 02:21:40 UTC
In certain cases, the method HttpWebRequest.GetRequestStream() throws
a WebException (timeout.) This only seems to happen in very specific
cases.
The main thread is executing an asynchronous HTTP POST request
specifying a callback. When that callback is invoked, it itself
executes a second HTTP POST request. That second HTTP request -
running within the separate thread (IO completion port callback) -
aborts because of this exception being thrown by GetRequestStream().
It doesn't matter whether the nested HTTP request is itself running
asynchronously or not. Note that we are using only asynchronous
versions for GetResponseStream(), not for GetRequestStream().
This is the exception being thrown:
System.Net.WebException: The operation has timed-out.
mscorlib.dll ! System.Threading.WaitHandle.WaitOne(int
millisecondsTimeout = 30000, bool exitContext = false)
system.dll ! System.Net.HttpWebRequest.GetRequestStream()
Unhandled Exception: System.Net.WebException: The operation has
timed-out.
at System.Net.HttpWebRequest.GetRequestStream()
[ user code, in async i/o callback ]
at System.Net.LazyAsyncResult.InvokeCallback()
at System.Net.LazyAsyncResult.InvokeCallback(Boolean
completedSynchronously, Object result)
at System.Net.HttpWebRequest.SetResponse(CoreResponseData
coreResponseData)
at System.Net.ConnectionReturnResult.SetResponse(ConnectionReturnResult
returnResult, HttpWebRequest request, CoreResponseData
coreResponseData)
at System.Net.Connection.NotifyRequestOfResponse(HttpWebRequest
request, ConnectionReturnResult& returnResult, Boolean
readDoneExpected)
at System.Net.Connection.ParseStreamData(ConnectionReturnResult&
returnResult)
at System.Net.Connection.ParseResponseData(ConnectionReturnResult&
returnResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
at System.Net.LazyAsyncResult.InvokeCallback()
at System.Net.LazyAsyncResult.InvokeCallback(Boolean
completedSynchronously, Object result)
at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
I also tried using the asynchronous API to invoke GetRequestStream().
IAsyncResult ar = httpReq.BeginGetRequestStream(null, null);
ar.AsyncWaitHandle.WaitOne(2000, false);
stream = httpReq.EndGetRequestStream(ar);
The result is the same: WaitOne() hangs for 2 seconds, then
EndGetRequestStream() for the predefined timeout. After that, the same
exception is thrown. Setting exitContext to true does not make a
difference.
If anyone has some hints on what could be the cause for this, it would
be truly appreciated. I've spent several weeks without finding a
solution :-(
thanks,
roman
a WebException (timeout.) This only seems to happen in very specific
cases.
The main thread is executing an asynchronous HTTP POST request
specifying a callback. When that callback is invoked, it itself
executes a second HTTP POST request. That second HTTP request -
running within the separate thread (IO completion port callback) -
aborts because of this exception being thrown by GetRequestStream().
It doesn't matter whether the nested HTTP request is itself running
asynchronously or not. Note that we are using only asynchronous
versions for GetResponseStream(), not for GetRequestStream().
This is the exception being thrown:
System.Net.WebException: The operation has timed-out.
mscorlib.dll ! System.Threading.WaitHandle.WaitOne(int
millisecondsTimeout = 30000, bool exitContext = false)
system.dll ! System.Net.HttpWebRequest.GetRequestStream()
Unhandled Exception: System.Net.WebException: The operation has
timed-out.
at System.Net.HttpWebRequest.GetRequestStream()
[ user code, in async i/o callback ]
at System.Net.LazyAsyncResult.InvokeCallback()
at System.Net.LazyAsyncResult.InvokeCallback(Boolean
completedSynchronously, Object result)
at System.Net.HttpWebRequest.SetResponse(CoreResponseData
coreResponseData)
at System.Net.ConnectionReturnResult.SetResponse(ConnectionReturnResult
returnResult, HttpWebRequest request, CoreResponseData
coreResponseData)
at System.Net.Connection.NotifyRequestOfResponse(HttpWebRequest
request, ConnectionReturnResult& returnResult, Boolean
readDoneExpected)
at System.Net.Connection.ParseStreamData(ConnectionReturnResult&
returnResult)
at System.Net.Connection.ParseResponseData(ConnectionReturnResult&
returnResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
at System.Net.LazyAsyncResult.InvokeCallback()
at System.Net.LazyAsyncResult.InvokeCallback(Boolean
completedSynchronously, Object result)
at System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
I also tried using the asynchronous API to invoke GetRequestStream().
IAsyncResult ar = httpReq.BeginGetRequestStream(null, null);
ar.AsyncWaitHandle.WaitOne(2000, false);
stream = httpReq.EndGetRequestStream(ar);
The result is the same: WaitOne() hangs for 2 seconds, then
EndGetRequestStream() for the predefined timeout. After that, the same
exception is thrown. Setting exitContext to true does not make a
difference.
If anyone has some hints on what could be the cause for this, it would
be truly appreciated. I've spent several weeks without finding a
solution :-(
thanks,
roman