Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] CompletableFuture 异步调用未录制 #589

Open
2 tasks
abstinencetang opened this issue Nov 27, 2024 · 1 comment
Open
2 tasks

[Bug] CompletableFuture 异步调用未录制 #589

abstinencetang opened this issue Nov 27, 2024 · 1 comment
Assignees
Labels
bug 🐞 Something isn't working

Comments

@abstinencetang
Copy link

abstinencetang commented Nov 27, 2024

Search before asking

  • I have searched the existing issues before asking.

AREX Test Service

AREX Java Agent (arextest/arex-agent-java)

Current Behavior

dubbo服务作为入口,方法里使用CompletableFuture进行了两次异步调用,第二次调用依赖第一次返回结果,发现只录制到了第一次的dubbo请求,第二次没有录上。

我们async接口内部实现是调用的dubbo方法,这里为了简单复现问题,实现了两个service做查询,配置动态类模拟录制过程。

controller类:
@GetMapping("test/test12")
public String test12() {
CompletableFuture future = async(true, "abc").thenApply(result -> {
System.out.println("1getValue:" + result);
return result + "-线程1";
}).thenCompose(this::getFutureValue);
String s = "";
try {
s = future.get();
System.out.println("result:" + s);
} catch (Exception e) {
throw new RuntimeException(e);
}
return "success";
}

public CompletableFuture<String> async(boolean isConfig, String txt) {
    return CompletableFuture.supplyAsync(() -> {
        if (isConfig) {
            return ConfigService.getConfig(txt);
        } else {
            return CacheService.getValue(txt);
        }
    }, this.executorService);
}

private CompletableFuture<String> getFutureValue(String result) {
    return async(false, result).thenApply(re -> {
        System.out.println("2getValue:" + re);
        return re + "-线程2";
    });
}

service1:
public class ConfigService {

private static final ConfigService configService = new ConfigService();

public static ConfigService getInstance() {
    return configService;
}

private ConfigService() {
}

public static String getConfig(String key) {
    return "config-" + key;
}

}

service2:
public class CacheService {

private static final CacheService cacheService = new CacheService();

public static CacheService getInstance() {
    return cacheService;
}

private CacheService() {
}

public static String getValue(String key) {
    return key + "-" + key;
}

}

Expected Behavior

CompletableFuture 两次异步调用都能录制

Steps To Reproduce

""

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!
@abstinencetang abstinencetang added the bug 🐞 Something isn't working label Nov 27, 2024
@lucas-myx lucas-myx self-assigned this Dec 10, 2024
@lucas-myx
Copy link
Collaborator

你好 感谢反馈,thenCompose本身就是异步线程创建的,内部又嵌套了一层async(false, result)异步方法,是否可以平铺开,怀疑是嵌套回调无法识别到线程的切换

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants