Saturday, March 8, 2014

A Gotcha with Enabling J2EE session in Adobe ColdFusion on Apache Tomcat

I've spent a bit of time over the past month or so playing with setting up a couple of my development systems to run Railo and Adobe ColdFusion 10 on a stock install of Apache Tomcat 7. In the case of ACF10, my interest in running on stock Tomcat is based on a desire get away from the custom-built and now outdated version of Tomcat Adobe (unwisely, in my opinion) bundles with ACF10. This past week I bumped into a bit of a gotcha that took me quite a bit of time to track down and solve. In the hopes of helping others avoid this same problem and so that I don't forget it, I'll share what I ran into and how to solve it.

The symptoms I was seeing were that as soon as I enabled J2EE sessions in the CF administrator and then subsequently stopped Tomcat for any reason, Tomcat would no longer start cleanly,it was no longer bringing up the context running ACF, and because it was not starting cleanly it would also not shutdown cleanly. As weird as this seemed (and sounds, I realize), this was very repeatable. I had it down to something I could reproduce in under 5 minutes: set up a clean new Tomcat install, deploy ACF10 on it via a WAR file, sign into the CF admin, enable J2EE sessions, stop Tomcat... and it would no longer start. There was nothing in the ${CATALINA_BASE}/logs/catalina.out log file indicating what was wrong; it just looked like as Tomcat began starting, it would hang.

It seemed like something about turning on J2EE sessions in ACF10 was breaking Tomcat. Based on a suggestion from a co-worker, I removed write permissions for the user under which Tomcat was running from all folders under ${CATALINA_BASE} except the ./logs/ and ./webapps/ folders, in an attempt to see if I could determine where the breakage was occurring. On starting Tomcat, I noticed a complaint in the ${CATALINA_BASE}/logs/catalina.out log file about not being able to write to folder ${CATALINA_BASE}/work/Catalina/localhost/_. Looking in that folder, I found a file named SESSIONS.ser and doing a bit of Googling, I came across a short blog post dealing with session persistence across Tomcat-restarts.

I'm not going to pretend that I know why Tomcat would have session persistence enabled across restarts, or why I might want to persist sessions across restarts (I really can't come up with a scenario where I would want that), or why enabling J2EE sessions in ACF10 would seem to break this persistence... but clearly it does. To disable this persistence, the context(s) within Tomcat on which ACF10 is enabled need to include a session manager component specifically configured to disable this persistence:

<Manager pathname="" />

This is touched upon in the Apache Tomcat docs here.