Skip to content

Commit f8f6139

Browse files
authored
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 8a5f777 commit f8f6139

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private static StructOrError<CdsUpdate.Builder> parseNonAggregateCluster(
215215
continue;
216216
}
217217
if (threshold.hasMaxRequests()) {
218-
maxConcurrentRequests = (long) threshold.getMaxRequests().getValue();
218+
maxConcurrentRequests = Integer.toUnsignedLong(threshold.getMaxRequests().getValue());
219219
}
220220
}
221221
}

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

+19
Original file line numberDiff line numberDiff line change
@@ -4001,6 +4001,25 @@ public void sendToBadUrl() throws Exception {
40014001
client.shutdown();
40024002
}
40034003

4004+
@Test
4005+
public void circuitBreakingConversionOf32bitIntTo64bitLongForMaxRequestNegativeValue() {
4006+
DiscoveryRpcCall call = startResourceWatcher(XdsClusterResource.getInstance(), CDS_RESOURCE,
4007+
cdsResourceWatcher);
4008+
Any clusterCircuitBreakers = Any.pack(
4009+
mf.buildEdsCluster(CDS_RESOURCE, null, "round_robin", null, null, false, null,
4010+
"envoy.transport_sockets.tls", mf.buildCircuitBreakers(50, -1), null));
4011+
call.sendResponse(CDS, clusterCircuitBreakers, VERSION_1, "0000");
4012+
4013+
// Client sent an ACK CDS request.
4014+
call.verifyRequest(CDS, CDS_RESOURCE, VERSION_1, "0000", NODE);
4015+
verify(cdsResourceWatcher).onChanged(cdsUpdateCaptor.capture());
4016+
CdsUpdate cdsUpdate = cdsUpdateCaptor.getValue();
4017+
4018+
assertThat(cdsUpdate.clusterName()).isEqualTo(CDS_RESOURCE);
4019+
assertThat(cdsUpdate.clusterType()).isEqualTo(ClusterType.EDS);
4020+
assertThat(cdsUpdate.maxConcurrentRequests()).isEqualTo(4294967295L);
4021+
}
4022+
40044023
@Test
40054024
public void sendToNonexistentServer() throws Exception {
40064025
// Setup xdsClient to fail on stream creation

0 commit comments

Comments
 (0)