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

解决abortProcess的并发问题 #2957

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ protected Object getExpressionResult(String express, Advice advice, double cost)
* @return true 如果超过或者达到了上限
*/
protected boolean isLimitExceeded(int limit, int currentTimes) {
return currentTimes >= limit;
//正常来讲,只需要判断currentTimes == limit即可,currentTimes如果是准确的(不能使用process.times().get()),
//那么不会出现自增时跳过limit的问题,为了应对未知的极端情况,仍旧加上currentTimes - limit > 100,以防万一
return limit <= 0 || currentTimes == limit || currentTimes - limit > 100;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ private void finishing(ClassLoader loader, Advice advice) {
}
if (conditionResult) {
// 满足输出条件
process.times().incrementAndGet();
// TODO: concurrency issues for process.write
process.appendResult(traceEntity.getModel());

int times = process.times().incrementAndGet();
// 是否到达数量限制
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
// TODO: concurrency issue to abort process
if (isLimitExceeded(command.getNumberOfLimit(), times)) {
abortProcess(process, command.getNumberOfLimit());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ private void finishing(Advice advice) {
StackModel stackModel = ThreadUtil.getThreadStackModel(advice.getLoader(), Thread.currentThread());
stackModel.setTs(LocalDateTime.now());
process.appendResult(stackModel);
process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
int times = process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), times)) {
abortProcess(process, command.getNumberOfLimit());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private void afterFinishing(Advice advice) {
isFirst = false;
}

process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
int times = process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), times)) {
abortProcess(process, command.getNumberOfLimit());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private void watching(Advice advice) {
}

process.appendResult(model);
process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
int times = process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), times)) {
abortProcess(process, command.getNumberOfLimit());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ private void watching(Advice advice) {
model.setAccessPoint(AccessPoint.ACCESS_AFTER_THROWING.getKey());
}
arthasStreamObserver.appendResult(model);
arthasStreamObserver.times().incrementAndGet();
if (isLimitExceeded(watchRequestModel.getNumberOfLimit(), arthasStreamObserver.times().get())) {
int times = arthasStreamObserver.times().incrementAndGet();
if (isLimitExceeded(watchRequestModel.getNumberOfLimit(), times)) {
String msg = "Command execution times exceed limit: " + watchRequestModel.getNumberOfLimit()
+ ", so command will exit.\n";
arthasStreamObserver.end();
Expand Down
Loading