dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

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

Open CycleMaker opened this issue 1 year ago • 1 comments

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 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

CycleMaker avatar Apr 22 '24 09:04 CycleMaker

Yes, it has been updated since Triple protocol introduced. You're welcome to update the comment here.

AlbumenJ avatar May 08 '24 03:05 AlbumenJ