Eternal 'red ring of death' with slow Servlets

(related to
this post
)

In my application I open a URL using ‘Window.open(new ExternalResource(url))’. Behind the url is a servlet (I use embedded Jetty), with following code:

[code]

        response.setContentType("plain/text");
        response.setHeader("Content-Disposition", "attachment; fileName="test.txt");

        ServletOutputStream out = response.getOutputStream();
        out.println("header");
        out.flush();

        response.setStatus(HttpServletResponse.SC_OK);

[/code](response being a HttpServletResponse)

And this works perfectly. However, if I add a ‘sleep’ to this servlet so that the request takes long enough to start the spinning ‘’ in the top-right corner of my application, this spinning '’ just stays there, even after the data associated with the URL is downloaded.

So, if I change the servlet to:


            response.setContentType("plain/text");
            response.setHeader("Content-Disposition", "attachment; fileName="test.txt");
            
            Thread.sleep(5000);

            ServletOutputStream out = response.getOutputStream();
            out.println("header");
            out.flush();

            response.setStatus(HttpServletResponse.SC_OK);

I get the same content that is downloaded, but my application doesn’t do anything anymore, except displaying a red spinning ‘*’.

Why the sleep? If you look at the related post (
this one
), it turned out that the request in this particular case took quite some time to complete, and it always resulted in a spinning ‘*’. I can only reproduce this on Chrome (I’m using version 18.0.1025.168, but it’s aslo the case with older versions).

Any ideas on how to solve this?