Skip to content

Commit

Permalink
xds: fixed unsupported unsigned 32 bits issue for circuit breaker (#1…
Browse files Browse the repository at this point in the history
…1735)

Added change for circuit breaking by converting signed 32-bit Int to Unsigned 64-bit Long For MaxRequest negative value ( -1)

Fixes #11695
  • Loading branch information
vinodhabib authored Dec 17, 2024
1 parent 8a5f777 commit f8f6139
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xds/src/main/java/io/grpc/xds/XdsClusterResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
continue;
}
if (threshold.hasMaxRequests()) {
maxConcurrentRequests = (long) threshold.getMaxRequests().getValue();
maxConcurrentRequests = Integer.toUnsignedLong(threshold.getMaxRequests().getValue());
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4001,6 +4001,25 @@ public void sendToBadUrl() throws Exception {
client.shutdown();
}

@Test
public void circuitBreakingConversionOf32bitIntTo64bitLongForMaxRequestNegativeValue() {
DiscoveryRpcCall call = startResourceWatcher(XdsClusterResource.getInstance(), CDS_RESOURCE,
cdsResourceWatcher);
Any clusterCircuitBreakers = Any.pack(
mf.buildEdsCluster(CDS_RESOURCE, null, "round_robin", null, null, false, null,
"envoy.transport_sockets.tls", mf.buildCircuitBreakers(50, -1), null));
call.sendResponse(CDS, clusterCircuitBreakers, VERSION_1, "0000");

// Client sent an ACK CDS request.
call.verifyRequest(CDS, CDS_RESOURCE, VERSION_1, "0000", NODE);
verify(cdsResourceWatcher).onChanged(cdsUpdateCaptor.capture());
CdsUpdate cdsUpdate = cdsUpdateCaptor.getValue();

assertThat(cdsUpdate.clusterName()).isEqualTo(CDS_RESOURCE);
assertThat(cdsUpdate.clusterType()).isEqualTo(ClusterType.EDS);
assertThat(cdsUpdate.maxConcurrentRequests()).isEqualTo(4294967295L);
}

@Test
public void sendToNonexistentServer() throws Exception {
// Setup xdsClient to fail on stream creation
Expand Down

0 comments on commit f8f6139

Please sign in to comment.