-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #3806 async sendError #3850
Conversation
Avoid using isHandled as a test withing sendError as this can be called asynchronously and is in a race with the normal dispatch of the request, which could also be setting handled status. Signed-off-by: Greg Wilkins <[email protected]>
The ErrorHandler was dispatching directly to a context from within sendError. This meant that an async thread can call sendError and be dispatched to within the servlet container at the same time that the original thread was still dispatched to the container. This commit fixes that problem by using an async dispatch for error pages within the ErrorHandler. However, this introduces a new problem that a well behaved async app will call complete after calling sendError. Thus we have ignore complete ISEs for the remainder of the current async cycle. Signed-off-by: Greg Wilkins <[email protected]>
@sbordet @janbartel This PR now fixes both problems: using isHandled and dispatching from within the ErrorHandler. |
Fixed the closing of the output after calling sendError. Do not close if the request was async (and thus might be dispatched to an async error) or if it is now async because the error page itself is async. Signed-off-by: Greg Wilkins <[email protected]>
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java
Outdated
Show resolved
Hide resolved
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelState.java
Show resolved
Hide resolved
@gregw I am not sure I understand the fix. Would be great if you add a comment describing the design of your solution, and how it fixes the problem. |
jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Greg Wilkins <[email protected]>
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java
Show resolved
Hide resolved
…06-async-sendError
Signed-off-by: Greg Wilkins <[email protected]>
See discussion starting here. I think we need a more involved solution. Both sync and async error dispatches need to be delayed until either sync returns or async completes... only then can an error dispatch be done - ie never from within sendError. |
Extending the delayed error dispatch approach to handle async sendError calls is promising, but it still needs careful though. Consider this sequence:
This looks OK and could also play out as:
But what if ERROR dispatch is itself async?
OK as well I think.... and with async Dispatch:
OK still. I think this can work. |
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
This PR somehow broke the HTTP/2 layer in this branch? |
Reworked HttpChannelState and sendError so that sendError is now just a change of state. All the work is done in the ErrorDispatch action, including calling the ErrorHandler. Async not yet working. Signed-off-by: Greg Wilkins <[email protected]>
Additional tests Signed-off-by: Greg Wilkins <[email protected]>
Converted ERRORED state to a separate boolean so it can be used for both Sync and Async dispatches. Removed ASYNC_IO state as it was just the same as DISPATCHED The async onError listener handling is now most likely broken. Signed-off-by: Greg Wilkins <[email protected]>
WIP making sendError simpler and more tests pass Signed-off-by: Greg Wilkins <[email protected]>
WIP handling async and thrown exceptions Signed-off-by: Greg Wilkins <[email protected]>
WIP passing tests Signed-off-by: Greg Wilkins <[email protected]>
…06-async-sendError Signed-off-by: Greg Wilkins <[email protected]>
Improved thread handling Signed-off-by: Greg Wilkins <[email protected]>
removed bad test Signed-off-by: Greg Wilkins <[email protected]>
Implemented error dispatch on complete properly more fixed tests Signed-off-by: Greg Wilkins <[email protected]>
sendError state looks committed Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
- Added resetContent method to leave more non-content headers during sendError - Fixed security tests Signed-off-by: Greg Wilkins <[email protected]>
- simplified the non dispatch error page writing. Moved towards being able to write async Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
See discussion in jakartaee/servlet#256 |
Updated handling of timeout errors. According to servlet spec, exceptions thrown from onTimeout should not be passed to onError, but just logged and ignored: If an exception is thrown while invoking methods in an AsyncListener, it is logged and will not affect the invocation of any other AsyncListeners. This changes several tests. Dispatcher/ContextHandler changes for new ERROR dispatch handling. Feels a bit fragile! Signed-off-by: Greg Wilkins <[email protected]>
Fixed tests in jetty-servlets Signed-off-by: Greg Wilkins <[email protected]>
Fixed tests in jetty-proxy Signed-off-by: Greg Wilkins <[email protected]>
Signed-off-by: Greg Wilkins <[email protected]>
…06-async-sendError
Fixed head handling Signed-off-by: Greg Wilkins <[email protected]>
reverted HttpMethod fromString Signed-off-by: Greg Wilkins <[email protected]>
reverted unnecessary changes Signed-off-by: Greg Wilkins <[email protected]>
Improved reason handling Signed-off-by: Greg Wilkins <[email protected]>
closing in favour of #3912 |
Issue #3806 async sendError
Avoid using isHandled as a test withing sendError as this can be
called asynchronously and is in a race with the normal dispatch of the
request, which could also be setting handled status.
Signed-off-by: Greg Wilkins [email protected]