Interrupted downloads when downloading a file from Web Api (remote host closed error 0x800704CD)

1

I have read near 20 other posts about this particular error, but most seem to be issues with the code calling Response.Close or similar, which is not our case. I understand that this particular error means that typically a user browsed away from the web page or cancelled the request midway, but in our case we are getting this error without cancelling a request. I can observe the error just after a few seconds, the download just fails in the browser (both Chrome and IE, so it's not browser specific).

We have a web api controller that serves a file download.

[HttpGet]
public HttpResponseMessage Download()
{
    //
    // Enumerates a directory and returns a Read-only FileStream of the download
    var stream = dataProvider.GetServerVersionAssemblyStream(configuration.DownloadDirectory, configuration.ServerVersion);

    if (stream == null)
    {
        return new HttpResponseMessage(HttpStatusCode.NotFound);
    }

    var response = new HttpResponseMessage(HttpStatusCode.OK)
                    {
                        Content = new StreamContent(stream)
                    };

    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
    response.Content.Headers.ContentDisposition.FileName = $"{configuration.ServerVersion}.exe";
    response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Application.Octet);
    response.Content.Headers.ContentLength = stream.Length;

    return response;
}

Is there something incorrect we are doing in our Download method, or is there something we need to tweak in IIS?

  • This happens sporadically. I can't observe a pattern, it works sometimes and other times it fails repeatedly.
  • The file download is about 150MB
  • The download is initiated from a hyperlink on our web page, there is no special calling code
  • The download is over HTTPS (HTTP is disabled)
  • The Web Api is hosted on Azure
  • It doesn't appear to be timing out, it can happen just after a second or two, so it's not hitting the default 30 second timeout values

I also noticed I can't seem to initiate multiple file downloads from the server at once, which is concerning. This needs to be able to serve 150+ businesses and multiple simultaneous downloads, so I'm concerned there is something we need to tweak in IIS or the Web Api.

exception
asp.net-web-api
download

1 Answer

0

I was able to finally fix our problem. For us it turned out to be a combination of two things: 1) we had several memory leaks and CPU intensive code in our Web Api that was impacting concurrent downloads, and 2) we ultimately resolved the issue by changing MinBytesPerSecond (see: https://blogs.msdn.microsoft.com/benjaminperkins/2013/02/01/its-not-iis/) to a lower value, or 0 to disable. We have not had an issue since.

answered on Stack Overflow Jun 6, 2018 by David Anderson

User contributions licensed under CC BY-SA 3.0