Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?
like image 857
woezelmann Avatar asked Mar 26 '15 10:03

woezelmann


People also ask

How does Tomcat shutdown work?

It simply means giving the process a chance to terminate normally (i.e. using a regular kill command with default TERM signal). The JVM can catch this signal and perform regular shutdown. The command is sent immediately from catalina.sh without delay.

How many HTTP requests can a Tomcat server handle?

The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.

How does Tomcat handle concurrent requests?

If still more simultaneous requests are received, Tomcat will accept new connections until the current number of connections reaches maxConnections . Connections are queued inside the server socket created by the Connector until a thread becomes avaialble to process the connection.

What is the use of shutdown port in Tomcat?

Tomcat listens on TCP port 8005 to accept shutdown requests. By connecting to this port and sending the SHUTDOWN command, all applications within Tomcat are halted. The shutdown port is not exposed to the network as it is bound to the loopback interface.


1 Answers

Apparently, you are not the only person to notice / comment on this behaviour; see this "tomcat-user" posting:

  • http://grokbase.com/t/tomcat/users/144b4jka4t/http-requests-held-up-during-tomcat-shutdown.

(Indeed, the similarities between that posting and your Question suggest that there is some connection between yourself and Andry Eng ...)

So clearly, this is "expected" behaviour in some sense.

Whether it is "correct" is a matter of opinion. And it is moot if the Tomcat developers don't agree with your opinion.

And, for what it is worth, posting rhetorical questions here about the "ideal" behaviour is also moot. Apparently, the Tomcat developers either don't hang out in StackOverflow / "tomcat-users" ... or they are not willing to debate the issue.


So what possible solutions do you have?

  • This linked Q&A explains a workaround - How to process servlet requests during long shutdown

  • You could open an issue on the Tomcat issue tracker. The snag is that your issue could sit on the list for months or years before it is addressed. Or it could be "dismissed".

    However, it doesn't look like anyone has submitted this as an issue in the past.

  • You could figure out how to modify Tomcat to reject new requests during shutdown. Then submit your (tested) changes as patches.

  • You could hire someone to do the work for you. For example, take a look at the people / organizations listed here: http://wiki.apache.org/tomcat/SupportAndTraining.

like image 122
Stephen C Avatar answered Sep 19 '22 13:09

Stephen C