tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Tomcat unaware that connection has been dropped
Date Thu, 09 Jul 2015 09:06:47 GMT
Tecno Brain wrote:
> I am running Tomcat 8.0.20 in Ubuntu with Java 1.8u45
> This server runs in Amazon EC2 behind an ELB (load balancer), although the
> cluster size is just one server.
> 
> My application allows to download some data in CSV format.
> The CSV data is generated on the fly, and there is no way to known in
> advance the size of the response. So, the data is an attachment.
> 
>  response.setContentType("text/csv;charset=utf-8");
> 
>  filename = "data.csv"
> 
>  response.setHeader("Content-Disposition", "attachment; filename=\"" +
> filename + ".csv\"");
> 
> 
> The download starts immediately but after 100 MB the browser stopped
> received data -my internet connection was not the best-, so I canceled the
> download as it was not progressing anymore.
> 
> Nevertheless, my web app keeps generating the CSV data, unaware that the
> connection has been dropped. I was expecting that my code would get an
> IOException when writing to the servlet OutputStream (which was wrapped by
> a BufferedOutputStream and wrapped by an OutputStreamWriter).
> 
> Is this a problem I can solve through the configuration of the NIO
> connector ?
> Or is this a problem of Amazon ELB that still consumes the stream even
> though it can't be forwarded to the browser anymore?

Yes, that kind of thing.  There may also be load-balancers, proxies, gateways, etc. 
between Tomcat and the end-user browser.
As long as Tomcat itself is able to write to that connection, there is no way for an 
application within Tomcat, to even find out that the ultimate client has gone away.

> 
> I don't remember having this problem when working with Apache HTTP as the
> load balancer. If I remember correctly, I would get an error indicating
> that the client closed the connection.

Yes, in some cases, because then there was less buffering in-between.

> 
> Any pointers are appreciated.
> 

If your generated files are really that big, I would suggest that the Tomcat side writes 
them to disk to a temporary file, and then returns to the client a short response, with a

link where it can retrieve that file.  Then there could be a separate cleanup procedure, 
which cleans up such temporary files when they are more than a certain age.



> -Jorge
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message