grpc / grpc-java

The Java gRPC implementation. HTTP/2 based RPC
https://grpc.io/docs/languages/java/
Apache License 2.0
11.48k stars 3.85k forks source link

xds: Circuit breaking doesn't support unsigned 32 bits #11695

Open ejona86 opened 1 week ago

ejona86 commented 1 week ago

If the control plane sends MAX_UINT32 as the max_requests for circuit breaking, grpc-java will treat it as a negative number. That should cause circuit breaking to trigger for all RPCs.

max_requests is a UInt32Value, but that's encoded as a signed int in Java. The code casts to long, but the sign is preserved: https://github.com/grpc/grpc-java/blob/4e8f7df589cbe5a192e705ab372f2b27957bf662/xds/src/main/java/io/grpc/xds/XdsClusterResource.java#L216

To treat it as a uint32, you essentially need to AND it with 0xFFFFFFFFL to make it unsigned. Since this is in xDS, we can use Integer.toUnsignedLong(int) (the main other convenience being Guava's UnsignedInts.toLong(int)).

b/372943501

CC @kannanjgithub