Mantis - Resin
Viewing Issue Advanced Details
4969 major always 02-28-12 07:32 06-19-12 13:03
closed 4.0.24  
none 4.0.29  
0004969: ServletContextListener.contextDestroyed() not called when resin is told to shutdown
I notice there is a bug (4331, and 4325 related) already logged and closed for this, but it was flagged as 'can not reproduce'. I can reproduce this reliably in my environment.

I have a ServletContextListener implementation that prints to StdOut, StdErr and throws an Exception in the contextDestroyed() method. I have added it as a listener in my web.xml, and the resin logs show that the context initialized message is being printed when I start the server.

The contextDestroyed() method does not get executed when I exit the server using " shutdown".
It does however get executed when I call " stop" and also when I dump a new war file into the web-apps directory forcing a restart.

Another interesting thing I can see is that killing the child server process (the one that the watchdog starts) manually using 'kill' calls the contextDestroyed() method. However, killing the parent watchdog process does NOT call it.

I do not have "shutdown-wait-max" defined anywhere in my resin.xml, so I assume this allows me to have 60s to perform shutdown code. I should be able to write to StdOut quite easily in that time.

I have also tested this using JVM shutdown hooks (Runtime.getRuntime().addShutdownHook) instead of contextDestroyed, and I get the exact same results.

This does not matter if you use or pass "shutdown" as an argument directly to resin.jar
This should behave as I have described as only "kill" should close uncleanly. This can be seen in this blog post: [^]

A workaround is to simply call stop on all your servers instead of shutdown.

06-19-12 13:03