https://bz.apache.org/bugzilla/show_bug.cgi?id=70362
Bug ID: 70362
Summary: AsyncListener gets onComplete, onError(null),
onComplete when an async dispatch ends after sendError
(regression from 66875)
Product: Tomcat 11
Version: 11.0.27
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P2
Component: Catalina
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: -------
Since the fix for bug 66875 (11.0.0-M14 / 10.1.16 / 9.0.83), an AsyncListener
receives onComplete, then onError with a null throwable, then onComplete again,
when an async dispatch calls sendError() and returns normally. The
AsyncListener contract treats onComplete as the end of the asynchronous
operation, so a listener expects it once and nothing after it.
Reproduction (Servlet API only, embedded Tomcat, one servlet mapped to /async
with asyncSupported=true):
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if (req.getDispatcherType() == DispatcherType.REQUEST) {
AsyncContext async = req.startAsync();
async.addListener(recordingListener); // records each callback
async.start(async::dispatch);
}
else {
resp.sendError(503);
}
}
GET /async answers 503. The listener records:
10.1.15: [onComplete]
10.1.16: [onComplete, onError(null), onComplete]
10.1.50: [onComplete, onError(null), onComplete]
11.0.27: [onComplete, onError(null), onComplete]
11.0.29: [onComplete, onError(null), onComplete]
Expected: [onComplete], as in 10.1.15.
Where it comes from (11.0.27):
1. AsyncContextImpl.doInternalDispatch: the dispatch returns and the request is
no longer async, so fireOnComplete() runs.
2. CoyoteAdapter.asyncDispatch then sees response.isError() (from sendError)
and calls asyncConImpl.setErrorState(ERROR_EXCEPTION, true). ERROR_EXCEPTION is
null, so listeners get onError with a null throwable after they were told the
request completed.
3. AbstractProcessor.asyncPostProcess completes the request again, and
fireOnComplete() runs a second time.
The response.isError() check comes from the 66875 fix. It looks like it needs
to skip a request whose async processing already completed during the dispatch.
Impact: a listener that records or releases something in onComplete does it
twice. Spring Framework's ServerHttpObservationFilter, for example, records the
request twice, and the Spring team asked for this to be reported here:
https://github.com/spring-projects/spring-framework/issues/37731
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]