-
Notifications
You must be signed in to change notification settings - Fork 78
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
Clarify ServletContextListener.contextDestroyed() call requirements on application startup failure #152
Comments
@glassfishrobot Commented |
@glassfishrobot Commented
Output on Tomcat/Jboss EAP 6:
Output on WildFly/Glassfish:
|
@glassfishrobot Commented
For further investigation, I added a third listener to see if it's initialised method get's called even after listener2 throws. Jetty's results are:
Which is probably not good. Either Listener3 should be initialised or it's destroy should not be called. I believe the OP is suggesting the results should be:
This would be good to have clarified |
@glassfishrobot Commented Thanks! |
@glassfishrobot Commented |
@glassfishrobot Commented Now given that we have the proper tools to do a proper cleanup, I think the developer has some responsibility to do some error management when required. For example, let say Listener2 does a multi-step initialization that could possibly leak resources, but one of the step fails with an unmanageable error. It should be up to Listener2 to attempt to do as much cleanup as possible, still within the "contextInitialized()" call, before rethrowing the error. At this point the startup of the application would still fail, but previously initialized ServletContextListeners would still have a chance to do their cleanup. And other applications living on the container will have a chance to survive without a restart of the JVM. Same if Listener2 fails during the contextDestroyed() call. We can't tell the outcome for all error scenarios, but other listeners would have the chance to do a proper cleanup and it becomes the developer's responsibility to tell if the error would require a container restart or not. |
@glassfishrobot Commented
|
@glassfishrobot Commented
|
@glassfishrobot Commented The important thing here is exactly which destroys get called? |
@glassfishrobot Commented Yes, the important thing is which destroys get called. |
@glassfishrobot Commented |
|
When migrating an application from Jboss EAP 6 (Tomcat based) to WildFly, I've encountered a change of behavior with ServletContextListeners that are not cleaned-up properly anymore (contextDestroyed() called) if an exception is thrown during application startup.
Steps to reproduce:
1 - Register two listeners (in web.xml)
2 - First one initializes correctly (contextInitialized())
3 - Second one throws a RuntimeException (contextInitialized())
4 - (On Jboss EAP 6): contextDestroyed() was called on both listeners.
5 - Failed application was undeployed successfully.
Behavior on different servlet implementations:
The 2.5 and 3.0+ servlet-api documents are not clear on the expected behavior.
and annotations.
In my opinion, the behavior I would expect is the following:
The text was updated successfully, but these errors were encountered: