Skip to content

Commit b86f474

Browse files
committed
fix abortProcess concurrency problem. #2957
1 parent 03eb94c commit b86f474

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractTraceAdviceListener.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.taobao.arthas.core.util.LogUtil;
1010
import com.taobao.arthas.core.util.ThreadLocalWatch;
1111

12+
import java.util.concurrent.atomic.AtomicBoolean;
13+
1214
/**
1315
* @author ralf0131 2017-01-06 16:02.
1416
*/
@@ -17,6 +19,7 @@ public class AbstractTraceAdviceListener extends AdviceListenerAdapter {
1719
protected final ThreadLocalWatch threadLocalWatch = new ThreadLocalWatch();
1820
protected TraceCommand command;
1921
protected CommandProcess process;
22+
private final AtomicBoolean processAborted = new AtomicBoolean(false);
2023

2124
protected final ThreadLocal<TraceEntity> threadBoundEntity = new ThreadLocal<TraceEntity>();
2225

@@ -99,7 +102,6 @@ private void finishing(ClassLoader loader, Advice advice) {
99102

100103
// 是否到达数量限制
101104
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
102-
// TODO: concurrency issue to abort process
103105
abortProcess(process, command.getNumberOfLimit());
104106
}
105107
}
@@ -112,4 +114,12 @@ private void finishing(ClassLoader loader, Advice advice) {
112114
}
113115
}
114116
}
117+
118+
@Override
119+
protected void abortProcess(CommandProcess process, int limit) {
120+
// Only proceed if this thread is the first one to set the flag to true
121+
if (processAborted.compareAndSet(false, true)) {
122+
super.abortProcess(process, limit);
123+
}
124+
}
115125
}

0 commit comments

Comments
 (0)