Search code examples
javatomcatservletstomcat7shutdown

HTTP requests held up during Tomcat shutdown


I am having an issue with Tomcat shutdown. Requests arriving while the servlet container is shutting down seem to be held up by the connector until container shutdown finishes.

The problem is, our servlet can take up to a minute to shut down, meaning connections arriving during this period are held for up to a minute.

Is this behavior correct/expected?

Wouldn't ideal Tomcat shutdown behavior be to

  1. let existing requests finish (as it already does), but
  2. reject new connections (instead of accepting and holding them)?

Solution

  • This is hardly desirable behavior. When shutting down it should stop accepting new connections but I guess there was some technical challenges in implementing it. Moot, anyway as noted.

    How we got past it is this:

    1. We have web servers in front of our tomcats. Get this in place, plan for long term if you do not, is my advice.
    2. have a way to tell the web server to drop a node (tomcat instance) from its list of round robin instances.
    3. after 3-4 minutes that tomcat node should be free (no new connections and old ones completed). We have a custom web server based on http://www.quickserver.org/ and it lets the back-end tomcats complete in process connections, though stops giving it new ones.
    4. when maintenance is up, we have another service on the agent to add the tomcat back to the web server(s) list of active servers.

    In our case we had a way to tell the server to reloads their configs. Other servers seem to have same https://serverfault.com/questions/108261/how-to-make-modification-take-affect-without-restart-nginx