dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[Bug] fix AbortPolicyWithReport may repeatedly jstack when threadPool is exhausted

Open code4china 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 issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo Java 3.2.12

Steps to reproduce this issue

  • run test case jStack_ConcurrencyDump_Active_10MinSilence, error will occurred immediately
@Test
    void jStack_ConcurrencyDump_Active_10MinSilence() {
        URL url = URL.valueOf("dubbo://admin:[email protected]:20880/context/path?dump.directory=/tmp&version=1.0.0&application=morgan&noValue=");
        AtomicInteger jStackCount = new AtomicInteger(0);
        AtomicInteger finishedCount = new AtomicInteger(0);
        AbortPolicyWithReport abortPolicyWithReport = new AbortPolicyWithReport("Test", url) {
            @Override
            protected void jstack(FileOutputStream jStackStream) {
                jStackCount.incrementAndGet();
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                }
            }
        };
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            4,
            4,
            0,
            TimeUnit.MILLISECONDS,
            new SynchronousQueue<>(),
            new NamedInternalThreadFactory("jStackRepeatFixedTest", false),
            abortPolicyWithReport);
        List<Future<?>> futureList = new LinkedList<>();
        for (int pos = 0; pos < 100; pos++) {
            try {
                futureList.add(threadPoolExecutor.submit(() -> {
                   finishedCount.incrementAndGet();
                }));
            } catch (Exception ignored) {
            }
        }
        futureList.stream().forEach(f -> {
            try {
                f.get(1000, TimeUnit.MILLISECONDS);
            } catch (Exception ignored) {
            }
        });
        System.out.printf("finishedCount: %d, jStackCount: %d\n", finishedCount.get(), jStackCount.get());
        Assertions.assertEquals(jStackCount.get(), 1);
    }

What you expected to happen

jStackCount must equal 1, because AbortPolicyWithReport will silence TEN_MINUTES_MILLS to avoid jstack's count

Anything else

This issue may cause JVM hang for a short time, it should be fixed as soon as possible!

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

code4china avatar Jul 23 '24 12:07 code4china

Can you help us fix this by submitting a pr?

wcy666103 avatar Jul 23 '24 12:07 wcy666103