Skip to content

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

@abstinencetang

Description

@abstinencetang

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!

Metadata

Metadata

Assignees

Labels

bug 🐞Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions