Bug 66323 - JDK_JAVA_OPTIONS grows unboundedly if webapp restarts Tomcat
Summary: JDK_JAVA_OPTIONS grows unboundedly if webapp restarts Tomcat
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.65
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-25 22:27 UTC by martin.dorey@hitachivantara.com
Modified: 2022-10-27 19:56 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description martin.dorey@hitachivantara.com 2022-10-25 22:27:16 UTC
The code at:

https://github.com/apache/tomcat/blob/09193e0514ac449df454184941bba492d9b20a85/bin/catalina.sh#L294

... that starts appending to JDK_JAVA_OPTIONS with:

JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED"

... eventually causes an error like:

     [exec] /opt/smu/tomcat/bin/catalina.sh: 1: eval: /opt/smu/javaTools/java/bin/java: Argument list too long

... if the Tomcat webapp restarts Tomcat enough times (on the order of 553) to break a 128 KiB limit on the length of a single environment variable that the shell is perhaps imposing.

I think this code was originally from Tomcat 9.0.0.M23 2017-07-03 in https://github.com/apache/tomcat/commit/4ad5264746e667a9874d6a56f6d52a7faa051b09 but was backported to Tomcat 8.5.24 2017-10-02 with https://github.com/apache/tomcat/commit/c3f3260481f14a9107994a6ee18f9e5ccc48c692.

We'll solve it without changing Tomcat, not least as our wrapper code is doing something similar with another environment variable, but I would have found the diagnosis easier if my web search for E2BIG "Argument list too long" catalina.sh had shown me the way, so I wanted to report it.
Comment 1 Mark Thomas 2022-10-27 09:16:19 UTC
Thanks for reporting this so others can benefit.

I think we can fix this for Tomcat 10.1.x onwards as the minimum Java version is 11. That means we don't need to export the environment variable and can just append those options to the command line.

I don't see a way to avoid this issue for Tomcat 9 and earlier where we are using this environment variable as a way to add these options for Java 9+ only.

Without knowing the details of the wrapper code, it does seem unusual that the new Tomcat process inherits the environment variables from the old Tomcat process. I am guessing there are reasons the wrapper behaves as it does but I'll note that other service wrappers are available that won't experience this issue.
Comment 2 Mark Thomas 2022-10-27 10:20:53 UTC
Fixed in:
- 10.1.x for 10.1.2 onwards
- 10.0.x for 10.0.28 onwards
Comment 3 Christopher Schultz 2022-10-27 19:56:53 UTC
I recently added a "restart" capability to my own web application. It uses JMX to request that Tomcat restart the current application, and the Tomcat process does not stop and restart. IF you are interested, ask about it on the users mailing list.