tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Preißer <>
Subject RE: EOFException in AjpNioProcessor
Date Sun, 22 Dec 2013 13:54:50 GMT
HI André,

> -----Original Message-----
> From: André Warnier []
> Sent: Sunday, December 22, 2013 12:25 PM
> To: Tomcat Users List
> Subject: Re: EOFException in AjpNioProcessor

> > I guess another way to phrase the question is, "what would cause a
> to get thrown?" I don't want to ignore it if it's trying to
> tell me something important.
> >
> > I am used to seeing "ClientAbortException:
> Broken pipe". Is the EOFException basically the same thing? My concern is
> that there might be some misconfiguration between the Apache front end
> and the Tomcat NIO connector that might be causing it.
> First I will state that I am not a Java specialist, so take the following with a
> grain of
> caution.
> This being said, I believe that these two exceptions mean two different
> things.
> A "broken pipe" exception occurs when your program can legitimately
> expect more data to be
> present on the stream being read, tries to read it, and gets back an error
> because the
> stream, unexpectedly, does not exist anymore (typically, because the other
> party supposed
> to write to that stream has gone away without warning).
> An EOF exception is different : you are reading from a stream. At some point,
> the read()
> returns an EOF condition, indicating that no more data is present.  That's not
> an
> exception yet, it is a normal condition for which you should be testing, and
> when it
> occurs you should stop reading.
> (I do not remember precisely how your code should test for this in Java.  It
> may be that
> an EOF is indicated by the fact that the read() returns 0 bytes.  Or maybe you
> should test
> explicitly by means of something like "if (stream.eof) then ..) after each
> read().
> But you do NOT stop reading, and you do one more read() nevertheless.
> /Then/ you get this
> exception, because now, you are trying to read /past/ the end of the
> file/stream (EOF).
> (It's like : you are approaching train-track crossing; you see the red light, and
> you
> should stop; but you don't, and you proceed nevertheless.  The EOF
> exception is the train
> that happens to be passing just then).

Note that the reason for a EOFException is slightly different than just reading from a stream
when there is no more data present.

In Java (and .Net), when you read from a Stream which is finished (there is no more data present),
read() returns -1. Even when you repeatedly call read(), you will still get -1, but no exception.
Normally you do just
    while ((read = > 0) { ...}
to test for the end of stream/data.

An EOFException however indicates that a higher logic was processing data but unexpectedly
received the end of stream. In this case, it is the AjpNioProcessor which reads from the AJP
connection and expects further AJP packets from the client, but the client unexpectedly closes
the exception instead of sending the required packets. This is why the EOFException is thrown.

This can indicate either a problem with the connection between Tomcat and the AJP client (e.g.
mod_jk, ISAPI redirector etc.), but I suspect the AJP client intentionally closes the connection
if e.g. the HTTP client which connected to the outer Webserver (HTTPD, IIS) aborted the HTTP
connection (or there was some other error) so this error is reflected at Tomcat (which can
therefore throw this exception). Otherwise Tomcat or the Webappp would not know that there
was an error and if it e.g. was sending a 10 GB file, it would continue to send it.

So, the EOFException here is not caused by an error in the code, but it should probably be
catched (like an IOException) to properly handle it.

Konstantin Preißer

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message