mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(elbv2): scope SetRulePriorities conflicts to the rule's listener (#4507)
* fix(elbv2): scope SetRulePriorities conflicts to the rule's listener
SetRulePriorities rejected a priority held by any rule in the region, so a
rule on one load balancer could not move to a priority used on another. AWS
scopes rule priorities to a listener ("A listener can't have multiple rules
with the same priority"), as CreateRule already did here.
Conflicts are now checked per listener, against that listener's rules that
are not part of the request. Two rules of the same listener given the same
priority in one request now fail with PriorityInUse instead of both being
applied.
* test(elbv2): keep SetRulePriorities compatibility tests in execution order
* fix(elbv2): check SetRulePriorities collisions against the concurrent rule map
The listener index lists are plain ArrayLists that CreateRule and DeleteRule
mutate without a lock, so iterating them could throw
ConcurrentModificationException. Iterate the region's ConcurrentHashMap and
filter by listener instead.
This commit is contained in:
1 parent
954bf8debb
commit
b830ade6cd
4 files changed
+197
-12
No files matched your search
@@ -752,18 +752,28 @@ public class ElbV2Service implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// check for collisions with rules NOT in the update set
|
||||
Set<String> updatingArns = arnToPriority.keySet();
|
||||
Set<Integer> newPriorities = new HashSet<>(arnToPriority.values());
|
||||
// priorities are unique per listener, so collisions are only checked among rules of the same listener
|
||||
Map<String, Set<Integer>> newPrioritiesByListener = new HashMap<>();
|
||||
for (Map.Entry<String, Integer> e : arnToPriority.entrySet()) {
|
||||
String listenerArn = regionRules.get(e.getKey()).getListenerArn();
|
||||
if (!newPrioritiesByListener.computeIfAbsent(listenerArn, k -> new HashSet<>()).add(e.getValue())) {
|
||||
throw new AwsException("PriorityInUse",
|
||||
"Priority " + e.getValue() + " is already in use.", 400);
|
||||
}
|
||||
}
|
||||
// iterate the concurrent region map, not the listener index lists, which CreateRule/DeleteRule mutate
|
||||
for (Rule existing : regionRules.values()) {
|
||||
if (!updatingArns.contains(existing.getRuleArn()) && !existing.isDefault()) {
|
||||
try {
|
||||
int existingPriority = Integer.parseInt(existing.getPriority());
|
||||
if (newPriorities.contains(existingPriority)) {
|
||||
throw new AwsException("PriorityInUse",
|
||||
"Priority " + existingPriority + " is already in use.", 400);
|
||||
}
|
||||
} catch (NumberFormatException ignored) { /* default rule */ }
|
||||
if (existing.isDefault() || arnToPriority.containsKey(existing.getRuleArn())) {
|
||||
continue;
|
||||
}
|
||||
Set<Integer> newPriorities = newPrioritiesByListener.get(existing.getListenerArn());
|
||||
if (newPriorities == null) {
|
||||
continue;
|
||||
}
|
||||
int existingPriority = Integer.parseInt(existing.getPriority());
|
||||
if (newPriorities.contains(existingPriority)) {
|
||||
throw new AwsException("PriorityInUse",
|
||||
"Priority " + existingPriority + " is already in use.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user