Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Commit 30b1874

Browse files
author
tbak
authored
Fixes #167 (Unsafe concurrent access to unknown lease collection in AssignableVMs class) (#168)
Fixes #167 (Unsafe concurrent access to unknown lease collection in AssignableVMs class)
1 parent 6eccfa7 commit 30b1874

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fenzo-core/src/main/java/com/netflix/fenzo/AssignableVMs.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void assignResult(TaskAssignmentResult result) {
8585
};
8686
private final ActiveVmGroups activeVmGroups;
8787
private String activeVmGroupAttributeName=null;
88-
private final List<String> unknownLeaseIdsToExpire = new ArrayList<>();
88+
private final BlockingQueue<String> unknownLeaseIdsToExpire = new LinkedBlockingQueue<>();
8989

9090
AssignableVMs(TaskTracker taskTracker, Action1<VirtualMachineLease> leaseRejectAction,
9191
long leaseOfferExpirySecs, int maxOffersToReject,
@@ -181,7 +181,8 @@ private int addLeases(List<VirtualMachineLease> leases) {
181181
void expireLease(String leaseId) {
182182
final String hostname = leaseIdToHostnameMap.get(leaseId);
183183
if(hostname==null) {
184-
unknownLeaseIdsToExpire.add(leaseId);
184+
logger.debug("Received expiry request for an unknown lease: {}", leaseId);
185+
unknownLeaseIdsToExpire.offer(leaseId);
185186
return;
186187
}
187188
internalExpireLease(leaseId, hostname);
@@ -253,13 +254,12 @@ private boolean isInActiveVmGroup(String attrValue) {
253254
}
254255

255256
private void expireAnyUnknownLeaseIds() {
256-
if(!unknownLeaseIdsToExpire.isEmpty()) {
257-
for(String leaseId: unknownLeaseIdsToExpire) {
258-
final String hostname = leaseIdToHostnameMap.get(leaseId);
259-
if(hostname!=null)
260-
internalExpireLease(leaseId, hostname);
261-
}
262-
unknownLeaseIdsToExpire.clear();
257+
List<String> unknownExpiredLeases = new ArrayList<>();
258+
unknownLeaseIdsToExpire.drainTo(unknownExpiredLeases);
259+
for(String leaseId: unknownExpiredLeases) {
260+
final String hostname = leaseIdToHostnameMap.get(leaseId);
261+
if(hostname!=null)
262+
internalExpireLease(leaseId, hostname);
263263
}
264264
}
265265

0 commit comments

Comments
 (0)