Skip to content

Commit

Permalink
Bug fix: fix 420, fix negative waitTime in RateLimiterController and …
Browse files Browse the repository at this point in the history
…WarmUpRateLimiterController

Signed-off-by: Carpenter Lee <[email protected]>
  • Loading branch information
CarpenterLee committed Jan 16, 2019
1 parent 303ae86 commit c45d64c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ public boolean canPass(Node node, int acquireCount, boolean prioritized) {
} else {
// Calculate the time to wait.
long waitTime = costTime + latestPassedTime.get() - TimeUtil.currentTimeMillis();
if (waitTime >= maxQueueingTimeMs) {
if (waitTime > maxQueueingTimeMs) {
return false;
} else {
long oldTime = latestPassedTime.addAndGet(costTime);
try {
waitTime = oldTime - TimeUtil.currentTimeMillis();
if (waitTime >= maxQueueingTimeMs) {
if (waitTime > maxQueueingTimeMs) {
latestPassedTime.addAndGet(-costTime);
return false;
}
Thread.sleep(waitTime);
// in race condition waitTime may <= 0
if (waitTime > 0) {
Thread.sleep(waitTime);
}
return true;
} catch (InterruptedException e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ public boolean canPass(Node node, int acquireCount, boolean prioritized) {
return true;
} else {
long waitTime = costTime + latestPassedTime.get() - currentTime;
if (waitTime >= timeOutInMs) {
if (waitTime > timeOutInMs) {
return false;
} else {
long oldTime = latestPassedTime.addAndGet(costTime);
try {
waitTime = oldTime - TimeUtil.currentTimeMillis();
if (waitTime >= timeOutInMs) {
if (waitTime > timeOutInMs) {
latestPassedTime.addAndGet(-costTime);
return false;
}
Thread.sleep(waitTime);
if (waitTime > 0) {
Thread.sleep(waitTime);
}
return true;
} catch (InterruptedException e) {
}
Expand Down

0 comments on commit c45d64c

Please sign in to comment.