Skip to content

[Bug] apm-jdk-threadpool-plugin conflicts with apm-jdk-forkjoinpool-plugin #13204

@GuoHaoZai

Description

@GuoHaoZai

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

OAP server (apache/skywalking)

What happened

CompletableFuture#runAsync(Runnable runnable,Executor executor)
If print logs in runnable, traceId will not be printed in the log

Essentially, there is a problem with java.util.concurrent.ThreadPoolExecutor#execute(Runnable runnable). If Runnable extends ForkJoinTask, Runnable will not be enhanced.

What you expected to happen

apm-jdk-threadpool-plugin enhances Runnable. If Runnable extends ForkJoinTask, Runnable will be enhanced by apm-jdk-forkjoinpool-plugin first, and then will not be enhanced by apm-jdk-threadpool-plugin, so the subsequent plugin will not work properly.

Image

How to reproduce

  1. skywalking 9.3.0
  2. enable apm-jdk-threadpool-plugin、apm-jdk-forkjoinpool-plugin
  3. Print traceId in the logback.xml
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinTask;

@Slf4j
@RestController
@RequestMapping(value = "/test")
public class TestController {

    ExecutorService executorService = Executors.newFixedThreadPool(10);

    @PutMapping("/test1")
    public void test() {
        executorService.submit(() -> {
            log.info("有traceId");
        });
        executorService.submit(new MyForkJoinTask(() -> {
            log.info("没有traceId: 继承ForkJoinTask");
        }));
        CompletableFuture.runAsync(() -> {
            log.info("没有traceId: CompletableFuture底层的AsyncRun继承ForkJoinTask");
        }, executorService);
    }

    public static class MyForkJoinTask extends ForkJoinTask<Void> implements Runnable {
        Runnable runnable;

        public MyForkJoinTask(Runnable runnable) {
            this.runnable = runnable;
        }

        @Override
        public void run() {runnable.run();}

        @Override
        public Void getRawResult() {return null;}
        @Override
        protected void setRawResult(Void value) {}
        @Override
        protected boolean exec() {return false;}
    }

}

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working and you are sure it's a bug!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions