Skip to content

Commit

Permalink
[UNDERTOW-1402] Make sure that response is done if AsyncContextImpl.o…
Browse files Browse the repository at this point in the history
…nAsyncComplete throws an error.
  • Loading branch information
fl4via committed Jun 13, 2019
1 parent 53f8544 commit 18cecc7
Showing 1 changed file with 29 additions and 22 deletions.
Expand Up @@ -297,33 +297,13 @@ public synchronized void completeInternal(boolean forceComplete) {
//basically if we are doing async IO we can't do a dispatch here, as then the IO thread can be racing
//with the dispatch thread.
//at all other times the dispatch is desirable
onAsyncComplete();
HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.responseDone();
try {
servletRequestContext.getOriginalRequest().closeAndDrainRequest();
servletRequestContext.getOriginalRequest().clearAttributes();
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
} catch (Throwable t) {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
}
onAsyncCompleteAndRespond();
} else {
servletRequestContext.getOriginalRequest().asyncRequestDispatched();
doDispatch(new Runnable() {
@Override
public void run() {
onAsyncComplete();

HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.responseDone();
try {
servletRequestContext.getOriginalRequest().closeAndDrainRequest();
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
} catch (Throwable t) {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
}
onAsyncCompleteAndRespond();
}
});
}
Expand Down Expand Up @@ -608,6 +588,33 @@ public void run() {
}
}

private void onAsyncCompleteAndRespond() {
final HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
try {
onAsyncComplete();
} catch (RuntimeException e) {
//handleError(e);
/*try {
response.sendError(StatusCodes.INTERNAL_SERVER_ERROR,
e.getMessage());
} catch (IOException ioException) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(ioException);
response.responseDone();
}
throw e;*/
UndertowServletLogger.REQUEST_LOGGER.failureDispatchingAsyncEvent(e);
} finally {
response.responseDone();
try {
servletRequestContext.getOriginalRequest().closeAndDrainRequest();
servletRequestContext.getOriginalRequest().clearAttributes();
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
} catch (Throwable t) {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
}
}
}

private void onAsyncComplete() {
final boolean setupRequired = SecurityActions.currentServletRequestContext() == null;
Expand Down

0 comments on commit 18cecc7

Please sign in to comment.