apache / apache/dubbo

[Feature] ThreadlessExecutor waitAndDrain method seems to not match its annotation.

Open
#14,119 1 comment 0 reactions 0 assignees View on GitHub
component/need-triage type/need-triage
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.