a

>>Bugs>> [Fixed in 1.2.18 and 1.1.25] ASP.NET crashes when downloading large file
Pages: 1   reply
Author [Fixed in 1.2.18 and 1.1.25] ASP.NET crashes when downloading large file
guest
Total Posts:
ASP.NET crashes when downloading large file
5/31/2007 1:38:58 PM
I have some pages on my site that allow the user to upload files and other pages that allow the user to download files.  On the upload pages, I am using NeatUpload and have the following lines in my web.config:
 
<httpModules>
   <addname="UploadHttpModule"type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload"/>
</httpModules>
 
The uploads work great, but it seems too cause a problem with the download pages. When the user downloads a large file (~100MB) it crashes the aspnet_wp process. If I take the above lines out of web.config, the download pages work fine. 
 
To download the file to the user, I am calling "Response.TransmitFile(filename);"
 
Here is the info from the event log (not very helpful, but you can see the process crashed)
aspnet_wp.exe (PID: 4776) stopped unexpectedly.
Source: ASP.NET 1.1.4322.0
Type: Error
Event ID: 1000
 
I do not know enough about what these lines do to know why they would cause this problem. Can you help?
 
Thanks,
John

 
Dean Brettle
Total Posts: 2015
Re: ASP.NET crashes when downloading large file
5/31/2007 5:50:41 PM
Thanks for the problem report.  A few questions:

Does the crash happen immediately after starting the download, or does it happen after some delay (e.g. several minutes)?
What version of NeatUpload are you using?
What browser are you using?

Can you email me (dean at brettle dot com) the download page, code behind, and Web.config (with sensitive info removed)?  Or if you have time to create a small project that just demonstrates the bug, that would be ideal?

Thanks!

 
Andreas Grüninger
Total Posts: 3
Re: ASP.NET crashes when downloading large file
6/8/2007 9:10:13 AM

This is a limitation of the web server.
You have to send the data in chunks.

I appended the source code example of Microsoft from the corresponding kb article.

I had to change just one line of code and it worked.

 

Andreas


        protected bool sendData(string filepath) {
            bool rc = false;
            System.IO.Stream iStream = null;

            // Buffer to read 10K bytes in chunk:
            byte[] buffer = new Byte[10000];
            // Length of the file:
            int length;
            // Total bytes to read:
            long dataToRead;
            // Identify the file to download including its path.
            //string filepath  = "DownloadFileName";

            // Identify the file name.
            string  filename  = System.IO.Path.GetFileName(filepath);
            try
            {
               // Open the file.
               iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
                        System.IO.FileAccess.Read,System.IO.FileShare.Read);
               // Total bytes to read:
               dataToRead = iStream.Length;
                // Nun löschen wir den Puffer ...
                Response.Clear();
               Response.ContentType = "application/octet-stream";
               Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
               // Read the bytes.
               while (dataToRead > 0)
               {
                  // Verify that the client is connected.
                  if (Response.IsClientConnected)
                  {
                     // Read the data in buffer.
                     length = iStream.Read(buffer, 0, 10000);
                     // Write the data to the current output stream.
                     Response.OutputStream.Write(buffer, 0, length);
                     // Flush the data to the HTML output.
                     Response.Flush();
                     buffer= new Byte[10000];
                     dataToRead = dataToRead - length;
                  }
                  else
                  {
                     //prevent infinite loop if user disconnects
                     dataToRead = -1;
                  }
               }
               rc = true;
            }
            catch (Exception ex)
            {
               // Trap the error, if any.
               if (log.IsErrorEnabled) log.Error("Error : " + ex.Message);
            }
            finally
            {
               if (iStream != null)
               {
                  //Close the file.
                  iStream.Close();
               }
            }
            return rc;
        }


 
Dean Brettle
Total Posts: 2015
Re: [Fixed in 1.2.18 and 1.1.25] ASP.NET crashes when downloading large file
6/16/2007 4:17:34 AM
Andreas' workaround is valid, but it shouldn't be necessary.  After working with John on the issue I determined that there was a bug like this in .NET 1.1 when sending large responses with WriteFile().  In .NET 1.1 SP1 (I think) MS added TransmitFile() to avoid the issue.  Unfortunately, it seems that TransmitFile() had the same bug when NeatUpload's UploadHttpModule was being used.  As of NeatUpload 1.2.18 and 1.1.25, this bug has been fixed.  The only side-effect of the fix is that sometimes responses larger than 1MB are not buffered.  Follow the link for more details.


 
Pages: 1   reply
a