[alibaba/arthas]通过http api执行dashboard命令30s一致返回,tunnelserver下正常返回

2024-08-05 51 views
4
环境信息
  • arthas-boot.jar 或者 as.sh 的版本: 3.6.7
  • Arthas 版本: 3.6.7
  • 执行arthas-boot的版本: 3.6.7
重现问题的步骤
  1. curl --location --request POST 'http://localhost:8563/api' \ --header 'Content-Type: text/plain' \ --data-raw '{ "action":"exec", "command":"dashboard" }'
期望的结果

期望http api 请求正常返回

实际运行的结果

30s左右才会返回数据

把异常信息贴到这里 pSe0Esx.png

回答

9
解决方案

您可以使用以下命令:

curl --location --request POST 'http://localhost:8563/api' --header 'Content-Type: text/plain' --data-raw '{"action":"exec","command":"dashboard", "execTimeout":30}'
现象原因

您可以看到代码如下com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java

Integer timeout = apiRequest.getExecTimeout();
if (timeout == null || timeout <= 0) {
    timeout = DEFAULT_EXEC_TIMEOUT;
}

com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java可以看到:

private boolean waitForJob(Job job, int timeout) {
    long startTime = System.currentTimeMillis();
    while (true) {
        switch (job.status()) {
            case STOPPED:
            case TERMINATED:
                return true;
        }
        if (System.currentTimeMillis() - startTime > timeout) {
            return false;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }
}

那是一个强制循环!

因此您使用DEFAULT_EXEC_TIMEOUT30000 毫秒,这就是您等待大约 30 秒的原因。

1

非常感谢您今天的帮助我