I'm testing ASP.NET (.NET 4) web-application under high load and have found that under some conditions HttpWebRequest.BeginGetResponse()
completes synchronously w/o throwing any exceptions.
After running the following code in multiple ASP.NET threads under high-load I've found "WEBREQUEST COMPLETED SYNC!" message in logs.
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
var result = webRequest.BeginGetResponse(internalCallback, userState);
if (result.CompletedSynchronously)
{
Trace.Error("WEBREQUEST COMPLETED SYNC!");
}
Pay attention that:
- In case thread pool capacity is reached an InvalidOperationException is thrown
- In case error occurs during connection corresponding exception is thrown
In my case there are no exceptions!
I've decompiled System.Net assembly and found that it is really possible under some conditions. But I didn't understand what these conditions mean (System.Net.Connection.SubmitRequest(HttpWebRequest request, bool forcedsubmit)
):
if (this.m_Free && this.m_WriteDone && !forcedsubmit && (this.m_WriteList.Count == 0 || request.Pipelined && !request.HasEntityBody && (this.m_CanPipeline && this.m_Pipelining) && !this.m_IsPipelinePaused))
{
this.m_Free = false;
needReConnect = this.StartRequest(request, true);
if (needReConnect == TriState.Unspecified)
{
flag = true;
this.PrepareCloseConnectionSocket(ref returnResult);
this.Close(0);
}
}
When & why is this possible?