1
votes

I am trying to understand the tomcat's (version 8.0.21) session persistence after I execute kill -9 . When I start my tomcat ( using startup.sh), I observe (randomly) http sessions of my web app ( which were created before the kill command execution) still being maintained. I understand this session persistence across restart, if I execute shutdown.sh to stop the tomcat and then bring the tomcat up again. My understanding of kill -9 is some what similar to 'power-off'. So my question is :

  1. Whether the standard manager implementation gets invoked just after kill -9, which tries to persist session before termination.
  2. Or I just get the previous session because my tomcat may have serialized the few session, (somewhere into its temp directory) while it was up earlier (before execution of kill -9).
1
On SIGKILL no such methods should be called (that is only applicable for SIGTERM).meskobalazs
Please, you should always state which version of Tomcat you are using. I don't know for sure, but the behaviour can certainly change between versions.dcsohl

1 Answers

1
votes

The Tomcat session manager documentation has lots to say on the topic. Here's a few relevant gems:

Tomcat provides two standard implementations of Manager for use — the default one stores active sessions, while the optional one stores active sessions that have been swapped out (in addition to saving sessions across a restart of Tomcat) in a storage location...

...

Whenever Apache Tomcat is shut down normally and restarted, or when an application reload is triggered, the standard Manager implementation will attempt to serialize all currently active sessions...

Emphasis mine - I think it's important to note that active sessions get serialized when you reload applications. If you've reloaded the application recently, and then do a kill -9 (which, as correctly noted in the comments, gives Tomcat no warning and no time to clean anything up, and thus should only be done as a last resort), then you will indeed see sessions persisting across the restart.

It is also possible that you may have the persistent storage manager configured:

In addition to the usual operations of creating and deleting sessions, a PersistentManager has the capability to swap active (but idle) sessions out to a persistent storage mechanism, as well as to save all sessions across a normal restart of Tomcat.

Though I will say that unless you did this configuration, or this install of Tomcat was preconfigured for you, this would not be the case.