[Feature] ThreadlessExecutor waitAndDrain method seems to not match its annotation.
- Dominant language
- Java
- Stars
- 41.6k
- Forks
- 26.4k
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 4
Description
### Pre-check
- [X] I am sure that all the content I provide is in English.
### Search before asking
- [X] I had searched in the [issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) and found no similar feature requirement.
### Apache Dubbo Component
Java SDK (apache/dubbo)
### Descriptions
This is the source code of the ThreadlessExecutor waitAndDrain method:
https://github.com/apache/dubbo/blob/ca7151e53166fc69079fefff074ee369aa29f134/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java#L52-L80
It seems that if waitAndDrain is called twice in a multi-threaded scenario, there will be no wait on the second execution because if the cas fails, it will return. Here is my test code:
> @Test
> void testV2() throws InterruptedException {
> new Thread(()->{
> try {
> executor.waitAndDrain(Long.MAX_VALUE);
> } catch (InterruptedException e) {
> throw new RuntimeException(e);
> }
> }).start();
> executor.waitAndDrain(Long.MAX_VALUE);
> System.out.println("wait not worked");
> }
There is no example in Dubbo where waitAndDrain is executed through the same threadlessExecutor across multiple threads, so there shouldn't be any issues. I don't know if this is a bug.
### Related issues
_No response_
### Are you willing to submit a pull request to fix on your own?
- [X] Yes I am willing to submit a pull request on my own!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
Contributor guide
Research direction
Start with dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java, especially waitAndDrain at lines 52–80, and run the multi-threaded test shown in the issue. Compare the method's behavior when two threads call it with its annotation, then define the expected waiting behavior and add a regression test demonstrating that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100