Discussion:
HttpWebRequest.GetRequestStream() throws WebException (timeout)
(too old to reply)
Roman Puttkammer
2003-08-07 02:21:40 UTC
Permalink
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
Roman Puttkammer
2003-08-07 13:43:40 UTC
Permalink
I found this only happens if one disables keep alives.
Post by Roman Puttkammer
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().
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
Feroze [MSFT]
2003-08-13 17:20:08 UTC
Permalink
Can you post more of your code here ? Did you set contentlength property ?
--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Post by Roman Puttkammer
I found this only happens if one disables keep alives.
Post by Roman Puttkammer
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().
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
Post by Roman Puttkammer
Post by Roman Puttkammer
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
Post by Roman Puttkammer
Post by Roman Puttkammer
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
Loading...