Repository navigation
Fix BZ 70362 - don't restart async error handling after a completed dispatch - #1264
codeconsole wants to merge 4 commits into
Conversation
…ispatch An asynchronous dispatch that called sendError() and returned normally had already notified the AsyncListeners of completion when the check added for BZ 66875 started async error handling, which notified them of an error with no throwable and then of completion a second time. https://bz.apache.org/bugzilla/show_bug.cgi?id=70362
|
Reproduced on main (f442523) with the servlet from the BZ: [onComplete, onError(null), onComplete]. With this PR: [onComplete], both for dispatch() on the request thread and via start(). Dispatches that return normally or throw behave as before, and TestAsyncContextImpl* passes. |
…te-once # Conflicts: # webapps/docs/changelog.xml
Cover the dispatch() made from a container-managed thread via start(), and check that an exception thrown by the async dispatch still reaches the listeners as onError before onComplete.
An asynchronous dispatch that recorded a failure and returned, or threw after an I/O error, notified the listeners of completion before the error handling in CoyoteAdapter.asyncDispatch notified them of the failure and of completion again. The notification of completion is now deferred in those cases so the error handling reports the failure first and completes once, with CoyoteAdapter firing the deferred notification if the error handling does not start. An error response with no exception no longer starts async error handling when the dispatch started a new async cycle and ended it with complete() or dispatch(), which replaced that with onError(null). The tests now wait for the access log entry, made once processing of the request has ended, rather than a fixed delay; check the throwable the listeners receive; cover dispatch() from start() both before and after the request thread exits service(); and check the in-progress async count returns to zero.
|
Thanks for testing it, including the
The tests wait for the access log entry rather than a fixed delay, check the throwable |
Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=70362
Since the fix for BZ 66875,
CoyoteAdapter.asyncDispatchstarts async error handling whenever the response is in an error state once an async dispatch returns. When that dispatch calledsendError()and returned normally without starting async processing again,AsyncContextImpl.doInternalDispatchhas already firedonComplete. The listeners are then told of an error with a null throwable and of completion a second time:[onComplete, onError(null), onComplete]. 10.1.15 and earlier delivered[onComplete].The same early
onCompleteaffects a dispatch that records a failure and returns (asInputBufferdoes for a read error the application swallows) and a dispatch that throws after an I/O error: the listeners getonComplete, thenonError, thenonCompleteagain. Separately,sendError()followed by a new async cycle that the dispatch ends withcomplete()ordispatch()gotonError(null)in that cycle.The change:
doInternalDispatchrecords that it completed the async processing, andasyncDispatchdoes not start error handling in that case.doInternalDispatchdefersonComplete. The error handling then reports the failure first and completes once. If the error handling does not start,asyncDispatchfires the deferredonCompleteitself, in afinally, soonCompleteis never lost (BZ 69121).complete()ordispatch().Tests, in
TestAsyncContextImpl:onErrorreceived and the in-progress async count.sendError()withdispatch()on the request thread, fromstart()before the request thread exitsservice(), and fromstart()after it exits:onComplete-. These fail onmainwithonComplete-onError-onComplete-.sendError(), then a new cycle ended withcomplete()or withdispatch():onComplete-. Fails onmainwithonError-onComplete-.IOExceptionthrown after the client has gone:onError-onComplete-with that exception. Fails onmainwithonComplete-onError-onComplete-.ServletException:onError-onComplete-with that exception and a 500, the same as onmain.onComplete-only, the same as onmain.With the change, 996 tests in 39 classes pass on NIO:
TestAsync*, everycatalina.connectortest (includingTestCoyoteAdapterAsyncErrorState),TestStandardHostValve,TestStandardWrapper,TestErrorReportValve,TestNonBlockingAPI,TestHttp11Processor,TestAsyncStateMachine, and the HTTP/2TestAsync*andTestStream*tests.ant validateis clean.It should be back-ported to 11.0.x, 10.1.x and 9.0.x, which carry the 66875 change.