HTTP requests delayed at Tomcat termination

I have a problem disconnecting Tomcat. The requests coming in from the servlet container are closed, it seems to be delayed by the connector until the container shutdown.

The problem is that our servlet can take up to a minute to close, which means connections arriving during this period are held for a minute.

Right / Expected Behavior?

Not ideal Tomcat disconnect behavior should be

  • allow existing queries (as already done), but
  • reject new connections (instead of accepting and holding them)?
+7
java tomcat servlets tomcat7 shutdown
source share
3 answers

This is hardly desirable. When shutting down, it should stop accepting new connections, but I assume that some technical problems arose in its implementation. Anyway, think about it.

How did we finish this:

  • We have web servers in front of our cats. Get it on the spot, plan for a long time, if you don't, this is my advice.
  • there is a way to tell the web server to omit the node (tomcat instance) from the list of round robin instances.
  • after 3-4 minutes, so that the tomcat node is free (new connections and old ones were not completed). We have our own web server, based on http://www.quickserver.org/ , and it allows background kittens to complete in technological connections, although it stops giving them new ones.
  • When the service is complete, we have another agent service to add tomcat back to the list of active server servers.

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

+1
source

Apparently, you are not the only person who notices / comments on this behavior; see this publication "tomcat-user":

(Indeed, the similarities between this post and your Question suggest that there is some connection between you and Andry Eng ...)

It is so clear that this is the “expected” behavior in a sense.

Whether this is “right” is a matter of opinion. And this is a moot point if Tomcat developers do not agree with your opinion.

And, for what it's worth, posting rhetorical questions here about “ideal” behavior is also a moot point. Apparently, the Tomcat developers either don't meet on StackOverflow / "tomcat-users" ... or they don't want to discuss the problem.


So what are the possible solutions you have?

  • This related Q&A explains a workaround - How to handle servlet requests on a long shutdown

  • You can open the problem in the Tomcat tracker. The disadvantage is that your problem may sit on the list for several months or years before it is considered. Or it may be "rejected."

    However, it does not look like someone has filed this as a problem in the past.

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

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

+5
source

This is the correct behavior. The client will send the request until it sees the server in the specified port.

The server will accept the request while it is running. Thus, some of the requests that were received at shutdown will be received, but will not be fully processed.

You will need to implement your own mechanism if you want to correctly handle these requests. You can use either a JMS queue or filters. The first request receive filter will first store (db / serialize) the request, and then process it. Later, when the server reboots, you can check requests that have not been processed, you can either process them or notify the client that it did not pass.

+2
source

All Articles