Procházet zdrojové kódy

Bug fix: fix 420, fix negative waitTime in RateLimiterController and WarmUpRateLimiterController

Signed-off-by: Carpenter Lee <hooleeucas@163.com>
master
Carpenter Lee před 5 roky
rodič
revize
c45d64c619
2 změnil soubory, kde provedl 11 přidání a 6 odebrání
  1. +6
    -3
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java
  2. +5
    -3
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java

+ 6
- 3
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/RateLimiterController.java Zobrazit soubor

@@ -58,17 +58,20 @@ public class RateLimiterController implements TrafficShapingController {
} 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) {
}


+ 5
- 3
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/controller/WarmUpRateLimiterController.java Zobrazit soubor

@@ -68,17 +68,19 @@ public class WarmUpRateLimiterController extends WarmUpController {
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) {
}


Načítá se…
Zrušit
Uložit