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");
                
                String imageId = request.getParameter(WebConstants.IMAGE_ID);
                ImageServer images = ImageServer.getServer();
                inStream = images.getImageData(imageId);
                
                byte[] bytes = new byte[1000];
                int bytesRead = inStream.read(bytes);
                while (bytesRead != -1) {
                        outStream.write(bytes,0,bytesRead);
                        bytesRead = inStream.read(bytes);
                }
                
                //appears to 'hang' here if client breaks connection
                outStream.flush();
                
        }
        catch (Throwable t) {
                //aborted connection type exceptions to log
                t.printStackTrace();
        }
        finally{
                //outStream.flush();
                //no debug output after here if flush is uncommented here
                inStream.close();
                //debug here appears OK
                outStream.close();
                //debug here never appears if client breaks connection
        }
}

The whole thing works perfectly in the situiation where the client
doesn't abort the connection.

I'm not asking anyone to solve my problem, I'm just trying to figure
out if I'm looking in the right place, possibly.

Could this potentially be where the problem lies ?

TIA

Lyallex

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

Reply via email to