Skip to content

Commit 982fb98

Browse files
committed
Synchronize isAPIThrottled method to handle concurrency issues
1 parent 66a7e62 commit 982fb98

File tree

1 file changed

+6
-7
lines changed
  • components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/throttling

1 file changed

+6
-7
lines changed

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/throttling/ThrottleDataHolder.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,19 @@ public void removeThrottledAPIKey(String key){
122122
throttledAPIKeysMap.remove(key);
123123
}
124124

125-
public boolean isAPIThrottled(String apiKey){
126-
boolean isThrottled = this.throttledAPIKeysMap.containsKey(apiKey);
127-
if(isThrottled) {
125+
public boolean isAPIThrottled(String apiKey) {
126+
Long timestamp = this.throttledAPIKeysMap.get(apiKey);
127+
if (timestamp != null) {
128128
long currentTime = System.currentTimeMillis();
129-
long timestamp = this.throttledAPIKeysMap.get(apiKey);
130-
if(timestamp >= currentTime) {
131-
return isThrottled;
129+
if (timestamp >= currentTime) {
130+
return true;
132131
} else {
133132
this.throttledAPIKeysMap.remove(apiKey);
134133
this.conditionDtoMap.remove(apiKey);
135134
return false;
136135
}
137136
} else {
138-
return isThrottled;
137+
return false;
139138
}
140139
}
141140

0 commit comments

Comments
 (0)