Check parent done condition before rejecting extraneous worker#5238
Merged
mpkorstanje merged 3 commits intomainfrom Dec 22, 2025
Merged
Check parent done condition before rejecting extraneous worker#5238mpkorstanje merged 3 commits intomainfrom
mpkorstanje merged 3 commits intomainfrom
Conversation
a30c5d1 to
8acb708
Compare
8acb708 to
270fe55
Compare
🔎 No tests executed 🔎🏷️ Commit: 6966ccb Learn more about TestLens at testlens.app. |
marcphilipp
approved these changes
Dec 21, 2025
Member
marcphilipp
left a comment
There was a problem hiding this comment.
Thanks for the detailed analysis! 👍
…tion-before-rejection
marcphilipp
added a commit
that referenced
this pull request
Jan 6, 2026
marcphilipp
added a commit
that referenced
this pull request
Jan 6, 2026
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.
The
WorkerThreadPoolHierarchicalTestExecutorServiceTests.limitsWorkerThreadsToMaxPoolSizeis flaky with a rather puzzling exception. While there are 3 permits available, 1 worker active thread. And yet the task rejected from the pool.This happens because, given the following test tree with a max of 3 workers, worker 1 starts execution at the root node:
When the child nodes are executed, there are 2 worker threads active and 1 available. The state at this point looks like this:
Both workers will then race each other trying to start 1 more. The winner of that race, child1 for the sake of argument, will then execute the
leaf1a, while the other thread will start working on the secondleaf1bnode.The state at this point looks like this:
Then a second race condition happens. After
leaf1ais done, the thread starts to wait forleaf1bto be finished. While it is waiting, it returns its worker lease and tries to compensate. At the time is tries to compensate, both worker 2 and worker 3 are still busy and the executor rejects the task.The state at this point looks like this:
Then a second race condition happens. After
leaf1ais done, the thread starts to wait forleaf1bto be finished. While it is waiting, it returns its worker lease and tries to compensate. At the time is tries to compensate, both worker 2 and worker 3 are still busy and the executor rejects the task.By the time the
RejectedExecutionHandleris invoked, worker 2 and 3 have finished their work and returned their leases. The state at this point looks like this:At this point the
executor.isShutdown() || workerLeaseManager.isAtLeastOneLeaseTaken()condition evaluates to false because 1) the executor is not shutdown and 2) there are no workers with active leases so an exception is thrown. By also checking if thedoneConditionof the worker that tried to start the new worker we can see that it was waiting in vain.I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations