title: AsyncContext and I/O error handling (when peer disconnects)
body: <p>I'm implementing Server-Sent Events using Servlet 3.0's <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/AsyncContext.html" rel="nofollow">javax.servlet.AsyncContext</a> interface.</p>
  
  <p>However I can't understand how I should handle I/O errors like peer disconnect.</p>
  
  <p>For a given <code>AsyncContext ac = request.startAsync()</code>, I can call <code>ac.getResponse().getWriter().print(something)</code> and then <code>ac.getResponse.getWriter().flush()</code> and it works fine. However when a client disconnects, I don't get an error - even if I attach a listener, its <code>onError</code> method is not called.</p>
  
  <p>I tested it with both Jetty 8 and Tomcat 7 and it seems that the disconnect from the client is not reported back to the application.</p>
  
  <p>What can be done to detect a communication error?</p>