Streaming large files breaks unexpectidely

0

In my application, I allow user to download large files approx (100MB's) which gets created dynamically and streams directly to the user without storing on the file system. Although it won't breaks all the time, it happens very rarely and very hard to replicate. In order to test it properly, i created a sandbox environment through following class:

public class MvcController : Controller
{
    public ActionResult TestWait(int timeToWait = 6000)
    {
        return new TestWaitResult(timeToWait);
    }
}

public class TestWaitResult : ActionResult
{
    int _timeToWait;
    object o = new object();
    TextWriter output;
    int _sleepTimer;
    public TestWaitResult(int timeToWait)
    {
        _timeToWait = timeToWait;
        _sleepTimer = 10;
    }

    public override void ExecuteResult(ControllerContext context)
    {
        context.HttpContext.Response.Buffer = context.HttpContext.Response.BufferOutput = false;
        output = context.HttpContext.Response.Output;

        while (true)
        {
            Log("Executing...");
            System.Threading.Thread.Sleep(_sleepTimer * 1000);
            if ((_timeToWait = _timeToWait - _sleepTimer) <= 0)
            {
                Log("Timetowait exceeds");
                break;
            }
        }
    }

    private void Log(string message)
    {
        lock (o)
        {

            output.WriteLine("<br/>{0} : {1}", DateTime.Now.ToString("hh:mm:ss.fff"), message);
            output.Flush();
        }
    } 

I tried to create the above code simpler to understand the problem.

I deployed the code on the server

http://msongs-test.apphb.com/mvc/testwait?timeToWait=6000

And, after testing it, i found that the response gets break unexpectedly after 10-15 minutes. And, I don't have any clue where it got breaks. I will be extremely happy to know the root cause of the problem.

PS: Although the code runs fine when i deploy it on my local IIS

Edit1: I checked the logs and found that two consecutive errors have been logged 1. HttpException: Server cannot set status after HTTP headers have been sent. 2. HttpException: The remote host closed the connection. The error code is 0x800704CD.

c#
asp.net-mvc
iis
.net-4.0
asked on Stack Overflow Feb 8, 2014 by Manish Rawat • edited Feb 9, 2014 by tereško

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0