My goal is to have reliably way to execute some code when http connection is broken due to client disconnection. As far as I understand fomr SseEmiter API and this issue: https://jira.spring.io/browse/SPR-13292 The way to do this is to register callback on SseEmiter.onCompletion method.
Unfortunately this callback is not called every time client drop connection. Such behavior suggest some race condition.
I have digged a bit and it seems there is a problem with Catalina asynchronous request dispatching. Result of method https://tomcat.apache.org/tomcat-8.5-doc/api/org/apache/catalina/connector/Request.html#isAsyncDispatching() is eventually used to determine if onCompletion callbacks should called. If there is a attempt to send new event from the server and it fails (because client is no longer connected) return value from this method seems to be non-deterministic.
Is this a bug or just lack of some configuration from my side?
This issue do not occur with Undertow.
EDIT: I'm using Tomcat 8.5.5 version.