UPDATE
See the bottom for the solution.
I'm trying to download reports in my ASP.Net MVC app in a loop. The first two always succeed, and the third always fails. It doesn't matter what order I run them in, it's always the third one that fails (which means that it's not the specific report, but the sequence that matters). When the reports succeed, they always come back in under 10 seconds, so it's not really a timeout. Please see the below code and scenarios.
Code
public Stream SomeMethodThatDownloadReports(string link)
{
using (var webClient = new WebClient())
{
webClient.Credentials = configuration.GetNetworkCredentialsForDownload();
try
{
return new MemoryStream(webC开发者_StackOverflowlient.DownloadData(link));
}
catch (Exception ex)
{
throw new ReportDownloadFailureException(string.Format("Problem accessing Report. Report Url = {0}", link), ex);
}
}
}
Scenarios
- Don't skip
- A - Succeeds in < 10 seconds
- B - Succeeds in < 10 seconds
- C - Times out
- Skip one
- A - Skip
- B - Succeeds in < 10 seconds
- C - Succeeds in < 10 seconds
- D - Times out
- Randomize
- B - Succeeds in < 10 seconds
- G - Succeeds in < 10 seconds
- H - Times out
UPDATE
As it turns out. The real reason for the timeouts was that NHibernate was trying to update objects even though it shouldn't have (long story) as a prerequisite to the call to the reports. For some reason, it managed to successfully flush the calls before the report was called for the first two calls, but by the third one, it always got behind and caused a deadlock in the database... hence the timeout.
Windows implements RFC-compliant http client which you are using in your code... RFC says max. 2 parallel connections to the same server are allowed at the same time... to chang that limit you need edit the registry (see for example: http://www.pctools.com/guides/registry/detail/536/)
精彩评论