-
Notifications
You must be signed in to change notification settings - Fork 582
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
Possible Bug with deferServletRequestListenerDestroyOnError #18281
Comments
I am on IBM Liberty 22.0.0.8
I found your post on StackOverflow advising to use this property and set it to true (https://stackoverflow.com/questions/43891297/weld-001303-no-active-contexts-for-scope-type-javax-enterprise-context-sessions). In my case, I use IBM Liberty server and if I dont have below in my server.xml When my JSF app throws a RuntimeException, I get :
When I add to my server.xml line:
But then I find this discussion on GitHub in which you suggest not using this setting set to true so I am confused and there is next to none explanation what this setting really does. Even More Confusing I have another application (the same one actually, just minor difference as one uses a RESTAPI and the other uses MQ to retrieve data but the rest is same). The other application server.xml does not need this property set at all and is handliner error pages just fine. Both are throwing the RuntimeException at the same place and under same condition, both have identically set pages, error pages, web.xml, faces-context.xml, both have same settings in server.xml, both running Liberty 22.0.0.8, yet one has this issue, the other does not. Could you elaborate please and much appreciated |
Hi @dinob68 , I agree that the explanation around this property could be improved. What it does: Why this matters: https://github.com/weld/core/blob/3.0/modules/web/src/main/java/org/jboss/weld/module/web/servlet/WeldInitialListener.java#L132-L139 (Linked 3.0.0, but I don't recall which version cdi-2.0 uses.) Webcontainer has a list of all ServletRequestListeners and call requestDestroyed for each at the end of the request. Here's where the problem begins: if an unhandled error occurs (ELException, for instance) during the processing of the request, it will call ServletRequestListener#requestDestroyed fairly early (compared to other servlet implementations). It then dispatches to the error handling, where the custom page will be processed. However, if this page uses any CDI beans, the ContextNotActiveException will occur since the CDI context was deactivated. Additionally, The servlet spec doesn't specifically mention when to call the ServletRequestListener methods during errors. Returning to the property, by delaying the ServletRequestListener#requestDestroyed (and hence WeldInitialListener ), we keep the CDI Context active which allows the beans to be available in the error page. The listener would be called after error handling finishes. In summary...
deferServletRequestListenerDestroyOnError: true (new behavior)
This particular bug (#18281) was created because we switched the default to true for EE9 and higher. The requestDestroyed calls failed to occur for Asynchronous Servlets. This problem was fixed last year. The property isn't defaulted to true for older versions because Websphere was strict in preserving existing behavior in order not to break any users. See Bill's comment here: #9929 (comment) Lastly, I'm not sure why the other application doesn't need this configuration given the description you provided. It's hard to tell why without more information. Perhaps you could collect a jsf, cdi, and webcontainer trace for both applications for me to compare? However, I might not be able to get back to you for a few weeks due to the holidays. Since you're using 22.0.0.8, there shouldn't be any harm in deferServletRequestListenerDestroyOnError (since the async problem had been solved and not other bugs identified) |
@volosied Thank you for clarifying this. |
Description
When deferServletRequestListenerDestroyOnError is true, and an error occurs during an asynchronous dispatch, then
ServletRequestListener.requestDestroyed() isn't called.
During an investigation a failing TCK test in PR #17210, I discovered this particular problem might be the root cause for that failure.
I've attached a sample app to the this issue (at the bottom). The logging from this sample app is shown in the snippets below.
WORKING Case: Liberty
-- deferServletRequestListenerDestroyOnError false (default)
FAILING Case: Liberty
-- deferServletRequestListenerDestroyOnError true
Tomcat
This scenario (and the app) appears to be valid case. I've compared Liberty, Tomcat, and Jetty.
EE9 App:
async-servletRequestListener-bug.war.zip
The text was updated successfully, but these errors were encountered: