Bug:Deadlocks occur when both engine and host startStopThreads values are set and the latter value is larger than the former #515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
apache-tomcat-10.0.21 version has been reproduced, I have not tried other versions
Reproduce
When starting tomcat as configured above, the situation shown in the image below will occur.
been stuck here⬆️⬆️⬆️
Then i used the Arthas tool to look at the threads and the results are shown below.
When starting tomcat, the current StandardServer instance object has been locked in LifecycleBase#start. When we do not set the startStopThreads value of StandardEngine, startStopThreads defaults to 1.
At this time, startStopExecutor in StandardEngine is actually an instance of InlineExecutorService (in fact, the current thread), ⬇️
tomcat/java/org/apache/catalina/core/ContainerBase.java
Line 882 in 22ceccc
so when StandardEngine starts its subcontainer StandardHost through the startStopExecutor thread pool, because it is the current thread, there is no problem when executing the StandardServer#reconfigureUtilityExecutor method.
tomcat/java/org/apache/catalina/core/StandardServer.java
Line 434 in 22ceccc
However, when the startStopExecutor in StandardEngine is not InlineExecutorService (ie Server#getUtilityExecutor()),
tomcat/java/org/apache/catalina/core/ContainerBase.java
Line 888 in 22ceccc
the StandardServer#reconfigureUtilityExecutor method is executed again(The host's startStopThreads value is greater than the engine's startStopThreads ), because the lock of the StandardServer instance has not been released at this time, resulting in a deadlock.