Tomcat 7.0.55 and 8.0.9 on Mac OS X Mavericks latest

I am doing server sent events with AsyncContext. Basic stuff is working.

I have set the timeout to be infinite so onTimeout() never happens. That’s fine 
— I don’t mind hangers on in this case.

Testing with curl, I can get a constant stream of events pretty much as they 
happen.

However, when I kill the curl, I see the socket that was being used go 
completely away according.

However, the background message pump is still going (I didn’t tell it to stop) 
but I noticed that no event listener method other than onComplete is called and 
that’s only when I explicitly complete the context.

I am planning on maintaining a large a large collection of AsyncContexts and 
had thought that the closing of the socket would have caused onError to be 
called — it does not get called under this circumstance.

In a busy system, when I’m running through the queue, I call 
PrinterWriter.checkError() to see if the client has gone away and then just 
complete the AsyncContext.

However, if there are no messages to send, then orphaned AsyncContext objects 
will build up. This is problematic since anyone authenticated can just 
connect/disconnect on SSE topics and run out of resources.

I can periodically scan through all saved AsyncContext objects and see if the 
PrintWriter on the response has an error, but this seems wrong.

Until I put the checkError into my code, a test message pump would happily call 
write on the PrinterWriter with no exceptions being thrown. I let the test run 
over night and still no exception on my log.

Question:
What errors cause onError to actually get called?

It seems wrong that PrintWriter on the response is not throwing an exception 
when there is an error.

Am I missing something? The socket has gone away (this is not the case of an 
long idle connection) and Tomcat must surely know that it did. Why does it not 
bubble this up to the AsyncListener?

I have not had a chance to try other Servlet engines but the behaviour was 
consistent between 7 & 8 latest.

I would really like to avoid having to do periodic scanning of AsyncContext to 
see if the the PrintWriter noticed there’s an error. This also would not seem 
to catch the case of a closed socket with no writes pending.

thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to