Skip to content

Commit 18015f8

Browse files
committed
chore: Cap gRPC inbound message size at ~2 GiB and metadata at 16 MiB
Extract named constants MAX_INBOUND_MESSAGE_SIZE (Integer.MAX_VALUE ≈ 2 GiB) and MAX_INBOUND_METADATA_SIZE (16 MiB) to make the caps explicit and prevent unbounded metadata from consuming heap on large dataset transfers.
1 parent 522c037 commit 18015f8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/java/ai/spice/SpiceClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,14 @@ public class SpiceClient implements AutoCloseable {
133133
// Cached Gson instance for JSON serialization (thread-safe)
134134
private static final Gson GSON = new Gson();
135135

136+
// 2 GiB cap for large dataset results (max safe signed-int value)
137+
private static final int MAX_INBOUND_MESSAGE_SIZE = Integer.MAX_VALUE;
138+
// 16 MiB cap for gRPC metadata/headers
139+
private static final int MAX_INBOUND_METADATA_SIZE = 16 * 1024 * 1024;
140+
136141
// Cached HttpClient for refresh operations (thread-safe, connection pooling)
137142
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
138-
.connectTimeout(Duration.ofSeconds(10))
143+
.connectTimeout(Duration.ofSeconds(15))
139144
.build();
140145

141146
// Pre-computed parameter field names to avoid string concatenation in hot path
@@ -274,8 +279,8 @@ private synchronized void buildFlightClient() {
274279
.keepAliveTime(30, java.util.concurrent.TimeUnit.SECONDS)
275280
.keepAliveTimeout(10, java.util.concurrent.TimeUnit.SECONDS)
276281
.keepAliveWithoutCalls(true)
277-
.maxInboundMessageSize(Integer.MAX_VALUE)
278-
.maxInboundMetadataSize(Integer.MAX_VALUE);
282+
.maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
283+
.maxInboundMetadataSize(MAX_INBOUND_METADATA_SIZE);
279284
ManagedChannel channel = channelBuilder.build();
280285

281286
try {

0 commit comments

Comments
 (0)