You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2022/10/27 12:51:07 UTC

[Bug 66327] New: Tomcat run as a windows service doesn't set the stack size accordingly

https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

            Bug ID: 66327
           Summary: Tomcat run as a windows service doesn't set the stack
                    size accordingly
           Product: Tomcat 9
           Version: 9.0.65
          Hardware: PC
            Status: NEW
          Severity: major
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: dragos.negoita@finastra.com
  Target Milestone: -----

Hello,

We developed a webapp which has been running in Tomcat for some time.
Recently, this application added a requirement of stack size increase which is
well handled by editing catalina.bat with a new line:
set "JAVA_OPTS=%JAVA_OPTS% -Xss3M"
for the case of debugging and implementation.

When the application is delivered and needs to be started as a windows service
it will encounter an issue regarding the stack size. The application will crash
with stack overflow exception, even if the stack size value is modified. I have
attached the screenshots of the service.

Tomcat used: is 9.0.65.
JDK used: openlogic-openjdk-8u342-b07 (this one is for the latest test, some
other versions were used during the investigation)

Java Options:
-Dcatalina.home=C:\tools\apache-tomcat-9.0.65
-Dcatalina.base=C:\tools\apache-tomcat-9.0.65
-Dignore.endorsed.dirs=C:\tools\apache-tomcat-9.0.65\endorsed
-Djava.io.tmpdir=C:\tools\apache-tomcat-9.0.65\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=C:\tools\apache-tomcat-9.0.65\conf\logging.properties



I have attached also a sample application to be put in the webapp folder.
It should list the numbers to 25000, through recursive calls.



Can you, please, help with this situation?

Regards,
Dragos.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

Dragos Negoita <dr...@finastra.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #6 from Dragos Negoita <dr...@finastra.com> ---
I apologize, it seems that the first attachment containing the sample
application didn't reach the logged issue.

So, if you use this application (only this, let's say) in webapp folder and
start Tomcat as a service, everything is in order? 
Does it list the numbers all the way to 25000?

I am asking because I tried a lot of ways to set the stack size value for the
case when the server is run as a service and every time this war fails to run
until the end.

Thank you!

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #2 from Dragos Negoita <dr...@finastra.com> ---
Created attachment 38425
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38425&action=edit
Tomcat service configuration

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #9 from Konstantin Kolinko <kn...@gmail.com> ---
1. First, I should apologize for a quick rant. I guess that I reacted on "Can
you help..." plea, as it is not something that I expect in a bug report. As I
and Mark wrote previously, help is provided elsewhere.

2. This is still no a valid bug report for Tomcat, as the service wrapper is a
third party component, provided by the Apache Commons Daemon project.

See:
https://tomcat.apache.org/bugreport.html#Third_party_components

3. Investigating further, my results are:

TLDR, overall it seems like the -Xss option is ignored when launching Java via
JNI API. Maybe Mark uses different version of Java.


(1) I am able to reproduce the issue using the web application provided by the
OP in comment 5, when using Apache Tomcat 9.0.68.

I am using July 2022 versions of Java. E.g. 1.8.0u345 from Eclipse Adoptium.
I have not updated to the October 2022 versions yet.

Expected result: when I change the stack size, I expect the iteration numbers
as printed in tomcat9-stdout.2022-10-27.log to change.

Actual result: the numbers go up to around 15300, no more.


(2) API used by Commons Daemon Procrun to launch JVM is JNI_CreateJavaVM.

https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#creating_the_vm

In the source code the call is
https://github.com/apache/commons-daemon/blob/master/src/native/windows/src/javajni.c#L817

As you can see the stack size is printed as a "-Xss" option for the command
line:

wsprintfA(iB[2], "-Xss%dk", dwSs);

(3) If I enable "debug" log level on the "Logging" tab of the configuration
dialog, I see the "-Xss" value being logged in commons-daemon.2022-10-27.log

[2022-10-27 18:43:41] [debug] ( javajni.c:419 ) [11416]
JNI_GetCreatedJavaVMs...
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[0]
-Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[1]
-Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 9.0
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[2]
-Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[3]
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[4]
-Djava.util.logging.config.file=C:\Program Files\Apache Software
Foundation\Tomcat 9.0\conf\logging.properties
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[5]
-Djava.class.path=C:\Program Files\Apache Software Foundation\Tomcat
9.0\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Tomcat
9.0\bin\tomcat-juli.jar
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[6] exit
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[7] abort
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[8] -Xms128m
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[9] -Xmx256m
[2022-10-27 18:43:41] [debug] ( javajni.c:817 ) [15152] JVM Option[10]
-Xss3072k
[2022-10-27 18:43:41] [debug] ( javajni.c:1003) [15152] argv[0] = start


As such, I think that the value is just being ignored by Java Runtime.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #13 from Konstantin Kolinko <kn...@gmail.com> ---
I filed an issue for Apache Commons Daemon:
https://issues.apache.org/jira/browse/DAEMON-451

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
                 OS|                            |All
             Status|NEW                         |RESOLVED

--- Comment #1 from Mark Thomas <ma...@apache.org> ---
Bugzilla is not a support forum. Please use the Apache Tomcat users mailing
list.

https://tomcat.apache.org/lists.html

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

Dragos Negoita <dr...@finastra.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #3 from Dragos Negoita <dr...@finastra.com> ---
It seems to be a Tomcat issue.
I already investigated this situation. All I can find is pieces of advice to
set stack size.

I doesn't work.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #12 from Konstantin Preißer <kp...@apache.org> ---
Hi,

FYI, on Windows, the default thread stack size is specified in the PE header
and can be set with the "editbin.exe /STACK" command [1] (and can be displayed
with the "dumpbin.exe /headers" command [2].
AFAIK this size will automatically be used for the stack size of the Main
thread.

For the "tomcat9.exe" service wrapper from Tomcat 9.0.65 (Windows x64), it is
displayed as follows (hex):

          100000 size of stack reserve
            1000 size of stack commit

i.e., a 1 MiB stack size. This seems to be the default at least when using MS
Visual C++ 2022. (The .NET [Core] app host for example uses a 1.5 MiB default
stack size for Windows x64.)

To set it e.g. to 4 MB stack (without changing the stack commit size), you can
call:

    editbin /STACK:4194304 tomcat9.exe


[1] https://learn.microsoft.com/en-us/cpp/build/reference/stack?view=msvc-170
[2] https://learn.microsoft.com/en-us/cpp/build/reference/headers?view=msvc-170

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #10 from Mark Thomas <ma...@apache.org> ---
I was using the latest Java 11 which does indeed suggest this is a Java bug. I
can think of a few possible workarounds but those are topics for the users
list.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #8 from Konstantin Kolinko <kn...@gmail.com> ---
Read this:
https://tomcat.apache.org/bugreport.html#Bugzilla_is_not_a_support_forum

Tomcat developers have nothing to do with your (mis)configuration. Ask fellow
users on the mailing list.



Just a few pointers:

> by editing catalina.bat with a new line:
> set "JAVA_OPTS=%JAVA_OPTS% -Xss3M"

A Tomcat running as a Windows Service is managed through a service wrapper
application. Its settings are stored in the Windows Registry and are managed
with tomcat9w.exe (GUI) or service.bat (CLI).

"catalina.bat" is only used when running a standalone Tomcat.

https://tomcat.apache.org/tomcat-9.0-doc/windows-service-howto.html#Tomcat_monitor_application

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #7 from Mark Thomas <ma...@apache.org> ---
Last time.

Setting the stack size via the properties page works. I have tested it (with a
simple JSP that does the same thing). Without the increased stack size it fails
with a StackOverflowError. Add the setting it works. Remove the setting it
fails again.

There is NO Tomcat bug here.

The users mailing list is the place to seek help.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|REOPENED                    |RESOLVED

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
A quick test confirms that this works as expected.

The users mailing list is the place to seek help.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #5 from Dragos Negoita <dr...@finastra.com> ---
Created attachment 38426
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38426&action=edit
Sample application.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 66327] Tomcat run as a windows service doesn't set the stack size accordingly

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66327

--- Comment #11 from Konstantin Kolinko <kn...@gmail.com> ---
FYI.

Retesting with latest Java, released in late October, the results are:

1. Java version does not matter.

The StackOverflowError is reproducible with OP's Sample application
using Apache Tomcat 9.0.70
using 64-bit
- Java 8u352 (server jvm),
- Java 11.0.17 (server jvm, client jvm)
from Eclipse Adoptium on Windows 10.

2. Thread matters.

2.1. Note that in the Sample application the recursive call is triggered from
contextInitialized(..) method of a ServletContextListener. With the default
configuration of Tomcat 9.0.70 the code runs on the "main" thread.

The thread name can be seen in the localhost.2022-**-**.log file, where the
StackOverflowError is logged.

> 06-Dec-2022 **:**:**.*** SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [stacktest.application.ApplicationServlet]
> java.lang.StackOverflowError
> ...

2.2. If I change Tomcat configuration to use a separate pool of threads to
start web applications, the web application starts successfully. It prints
numbers up to 25000, as expected. The configuration is done by adding
startStopThreads attribute to a Host, for example:

<Host ... startStopThreads="3">

For further reference, see
https://tomcat.apache.org/tomcat-9.0-doc/config/host.html#Common_Attributes

This is the workaround that I recommend for this issue.

2.3. Whether the stack size of the main thread can be configured, is a question
for the Commons Daemon project.

https://commons.apache.org/proper/commons-daemon/procrun.html

There is no Apache Tomcat bug here.


3. As a side note.

java.lang.Thread has a constructor that allows to specify the stackSize.

> public Thread(ThreadGroup group,
>              Runnable target,
>              String name,
>              long stackSize)
> @since 1.4

It may be that it will be useful to somebody.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org