Skip to content

Commit 7942b23

Browse files
committed
grpc-js-xds: Validate that endpoint weights sum to no more than 32 bit uint max per priority
1 parent 40feac7 commit 7942b23

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/grpc-js-xds/src/xds-stream-state/eds-state.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class EdsState extends BaseXdsStreamState<ClusterLoadAssignment__Output>
5050
*/
5151
public validateResponse(message: ClusterLoadAssignment__Output) {
5252
const seenLocalities: {locality: Locality__Output, priority: number}[] = [];
53+
const priorityTotalWeights: Map<number, number> = new Map();
5354
for (const endpoint of message.endpoints) {
5455
if (!endpoint.locality) {
5556
return false;
@@ -72,6 +73,12 @@ export class EdsState extends BaseXdsStreamState<ClusterLoadAssignment__Output>
7273
return false;
7374
}
7475
}
76+
priorityTotalWeights.set(endpoint.priority, (priorityTotalWeights.get(endpoint.priority) ?? 0) + (endpoint.load_balancing_weight?.value ?? 0));
77+
}
78+
for (const totalWeight of priorityTotalWeights.values()) {
79+
if (totalWeight >= 1<<32) {
80+
return false;
81+
}
7582
}
7683
return true;
7784
}

0 commit comments

Comments
 (0)