Bug:Deadlocks occur when both engine and host startStopThreads values are set and the latter value is larger than the former#515
Closed
aooohan wants to merge 2 commits into
Closed
Conversation
Contributor
|
Good idea, the sync is overloaded in that case so this is risky, and other operations already use a servicesLock item for this reason. |
Member
Author
|
@rmaucher Thank u for reviewing my PR, it's an honour to contribute PR to Tomcat. |
Contributor
|
Thanks a lot for your PR. Sorry, I forgot to close it after merging it manually. The fix will be in Tomcat 10.1.0-M16, 10.0.22, 9.0.64. Tomcat 8.5 is not affected since it doesn't have the utility executor feature. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.