Skip to content

Commit 137d129

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 137d129

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

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

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

136+
// Cap for large dataset results and metadata (~2 GiB, max safe signed-int value)
137+
private static final int MAX_INBOUND_MESSAGE_SIZE = Integer.MAX_VALUE;
138+
private static final int MAX_INBOUND_METADATA_SIZE = Integer.MAX_VALUE;
139+
136140
// Cached HttpClient for refresh operations (thread-safe, connection pooling)
137141
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
138-
.connectTimeout(Duration.ofSeconds(10))
142+
.connectTimeout(Duration.ofSeconds(15))
139143
.build();
140144

141145
// Pre-computed parameter field names to avoid string concatenation in hot path
@@ -274,8 +278,8 @@ private synchronized void buildFlightClient() {
274278
.keepAliveTime(30, java.util.concurrent.TimeUnit.SECONDS)
275279
.keepAliveTimeout(10, java.util.concurrent.TimeUnit.SECONDS)
276280
.keepAliveWithoutCalls(true)
277-
.maxInboundMessageSize(Integer.MAX_VALUE)
278-
.maxInboundMetadataSize(Integer.MAX_VALUE);
281+
.maxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
282+
.maxInboundMetadataSize(MAX_INBOUND_METADATA_SIZE);
279283
ManagedChannel channel = channelBuilder.build();
280284

281285
try {

0 commit comments

Comments
 (0)