Ensure AsyncListener#onError
does not return until dispatch completes
#34192
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
When a controller returns
Flux<ServerSentEvent>
,SseEmitter
is used to write events. If the connection drops, the write fails with IOException in a Spring MVC TaskExecutor thread while in parallel we also get a Servlet containerAsyncListener#onError
callback.In #32340,
WebAsyncManager
was enhanced to be protected in this race, so only one thread can dispatch. However, it is also crucial to ensure theonError
callback holds up until the dispatch completes regardless of who wins.WebAsyncManager#setConcurrentResultAndDispatch
guarantees this through synchronization, but when usingDeferredResult
, theonError
callback may not call that method at all if DeferredResult error handling finds the result is already set by the competing thread. As a result, the onError callback may exit the container thread before dispatch in the Spring MVC thread compltes, which leads to the stacktrace in #33421 (comment) and also in #34188.The issue does not apply when using
Callable
, e.g. viaStreamingResponseBody
as in that casesetConcurrentResultAndDispatch
is always called.The text was updated successfully, but these errors were encountered: