alibaba / alibaba/arthas

在使用trace命令的时候,对于方法里面有sleep操作的方法无法显示调用信息,日志也没有报错

Open
#2,806 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
37.6k
Forks
7.6k
Avg merge
1d 22h
Merged PRs (30d)
4

Description

- [x] 我已经在 [issues](https://github.com/alibaba/arthas/issues) 里搜索,没有重复的issue。

### 环境信息

* `arthas-boot.jar` 或者 `as.sh` 的版本: 3.7.2
* Arthas 版本: 3.7.2
* 操作系统版本: macOS 10.13.6 (Darwin Kernel Version 17.7.0)
* 目标进程的JVM版本: jdk1.8.0_162
* 执行`arthas-boot`的版本: 3.7.2

### 重现问题的步骤

1. 运行如下代码:
```
package com.mvp.service;

import java.util.concurrent.TimeUnit;

public class HqlParseMain {

public static void main(String[] args) throws InterruptedException {
String input ="SELECT ";
HqlParseMain parseTest = new HqlParseMain();

parseTest.doParse2(input);
}

private void doParse2(String input) throws InterruptedException {
while (true) {
System.out.println(input);
sleep();
}
}

private void sleep() throws InterruptedException {
TimeUnit.SECONDS.sleep(2);
}
}
```

> 输入trace命令,查看结果一直没有出现:
[arthas@17951]$ trace com.mvp.service.HqlParseMain doParse2
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 98 ms, listenerId: 1
一直等待不会出现调用结果的。

3. 代码改成:
```
package com.mvp.service;

import java.util.concurrent.TimeUnit;

public class HqlParseMain {

public static void main(String[] args) throws InterruptedException {
String input ="SELECT ";
HqlParseMain parseTest = new HqlParseMain();

while (true) {
parseTest.doParse2(input);
parseTest.sleep();
}
}

private void doParse2(String input) throws InterruptedException {
for (int i = 0; i < 100; i++) {
System.out.println(input);
}
}

private void sleep() throws InterruptedException {
TimeUnit.SECONDS.sleep(2);
}
}
```
输入trace命令就会正常出现结果:

> [arthas@17842]$ trace com.mvp.service.HqlParseMain doParse2
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 95 ms, listenerId: 1
`---ts=2024-02-29 17:36:43;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
`---[2.426401ms] com.mvp.service.HqlParseMain:doParse2()

### 期望的结果
第1步的方法也可以查看到调用信息。

### 实际运行的结果

参考上文的结果描述。

```
在日志没有发现异常,感觉问题应该跟java.lang.Thread有关。
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided HqlParseMain example on Java 8, then run the trace command against doParse2 while it calls sleep. Start by tracing the invocation handling and Thread-related behavior; done means trace reports the completed method call even when the method contains a two-second sleep, without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.