[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tomcat-user
Subject:    Re: How to close an out Stream if a client aborts
From:       "Johnny Kewl" <john () kewlstuff ! co ! za>
Date:       2008-06-30 13:09:30
Message-ID: 00af01c8dab2$8882da90$0300000a () animal
[Download RAW message or body]


----- Original Message ----- 
From: "Lyallex" <lyallex@gmail.com>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Monday, June 30, 2008 10:11 AM
Subject: How to close an out Stream if a client aborts


> Good Morning
> 
> Java 1.5.0_15
> Tomcat 5.5.26
> 
> I have a servlet that is used to serve up images from a database
> 
> If the client aborts the connection I get the usual 'broken pipe' type
> exceptions
> 
> The thing is that from my debug output it appears that the
> OutputStream to the client
> (instanceof ServletOutputStream) is neither flushed nor closed in this
> situation.
> I try to close all resources in a finally block but the debug after
> outStream.close never appears
> I guess I can understand why the stream is not flushed (there is no
> connection to flush it to)
> but I'm not sure why I can't close the stream, the javadoc doesn't
> really help ...
> The problem I have is that under heavy load the server crashes silently
> (no errors to the logs) and I'm trying to track down why this might be.
> If I get loads of unclosed OutputStreams containing uncommitted data
> this might be the problem. (yes/no?)
> Here's the basic code (logging and debug removed)
> 
> public void doService(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
> 
> 
>        ServletOutputStream outStream = null;
>        InputStream inStream = null;
> 
> try {
> outStream = response.getOutputStream();
> response.reset();
> response.setHeader("Expires", "-1");
> response.setHeader("Cache-Control", "no-cache");

Lyallax.... add this to your code as well

response.setContentLength(FileSize);

Its better coding... 

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic