Skip to content

Commit 112dccb

Browse files
vinodhabibejona86
authored andcommitted
xds: fixed unsupported unsigned 32 bits issue for circuit breaker (#11735)
Added change for circuit breaking by converting signed 32-bit Int to Unsigned 64-bit Long For MaxRequest negative value ( -1) Fixes #11695
1 parent 0de7bfe commit 112dccb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

xds/src/main/java/io/grpc/xds/XdsClusterResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
213213
continue;
214214
}
215215
if (threshold.hasMaxRequests()) {
216-
maxConcurrentRequests = (long) threshold.getMaxRequests().getValue();
216+
maxConcurrentRequests = Integer.toUnsignedLong(threshold.getMaxRequests().getValue());
217217
}
218218
}
219219
}

xds/src/test/java/io/grpc/xds/GrpcXdsClientImplTestBase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3972,6 +3972,25 @@ public void sendToBadUrl() throws Exception {
39723972
client.shutdown();
39733973
}
39743974

3975+
@Test
3976+
public void circuitBreakingConversionOf32bitIntTo64bitLongForMaxRequestNegativeValue() {
3977+
DiscoveryRpcCall call = startResourceWatcher(XdsClusterResource.getInstance(), CDS_RESOURCE,
3978+
cdsResourceWatcher);
3979+
Any clusterCircuitBreakers = Any.pack(
3980+
mf.buildEdsCluster(CDS_RESOURCE, null, "round_robin", null, null, false, null,
3981+
"envoy.transport_sockets.tls", mf.buildCircuitBreakers(50, -1), null));
3982+
call.sendResponse(CDS, clusterCircuitBreakers, VERSION_1, "0000");
3983+
3984+
// Client sent an ACK CDS request.
3985+
call.verifyRequest(CDS, CDS_RESOURCE, VERSION_1, "0000", NODE);
3986+
verify(cdsResourceWatcher).onChanged(cdsUpdateCaptor.capture());
3987+
CdsUpdate cdsUpdate = cdsUpdateCaptor.getValue();
3988+
3989+
assertThat(cdsUpdate.clusterName()).isEqualTo(CDS_RESOURCE);
3990+
assertThat(cdsUpdate.clusterType()).isEqualTo(ClusterType.EDS);
3991+
assertThat(cdsUpdate.maxConcurrentRequests()).isEqualTo(4294967295L);
3992+
}
3993+
39753994
@Test
39763995
public void sendToNonexistentServer() throws Exception {
39773996
// Setup xdsClient to fail on stream creation

0 commit comments

Comments
 (0)