Skip to content

chore: Support configuration for max grpc inbound message #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sdk/src/main/java/io/dapr/config/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,24 @@ public class Properties {
"DAPR_HTTP_CLIENT_MAX_IDLE_CONNECTIONS",
DEFAULT_HTTP_CLIENT_MAX_IDLE_CONNECTIONS);



/**
* Dapr's default maximum inbound message size for GRPC in bytes.
*/
public static final Property<Integer> GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES = new IntegerProperty(
"dapr.grpc.max.inbound.message.size.bytes",
"DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES",
4194304);

/**
* Dapr's default maximum inbound metadata size for GRPC in bytes.
*/
public static final Property<Integer> GRPC_MAX_INBOUND_METADATA_SIZE_BYTES = new IntegerProperty(
"dapr.grpc.max.inbound.metadata.size.bytes",
"DAPR_GRPC_MAX_INBOUND_METADATA_SIZE_BYTES",
8192);

/**
* Mechanism to override properties set in a static context.
*/
Expand Down
31 changes: 24 additions & 7 deletions sdk/src/main/java/io/dapr/utils/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@
import static io.dapr.config.Properties.GRPC_KEEP_ALIVE_TIMEOUT_SECONDS;
import static io.dapr.config.Properties.GRPC_KEEP_ALIVE_TIME_SECONDS;
import static io.dapr.config.Properties.GRPC_KEEP_ALIVE_WITHOUT_CALLS;
import static io.dapr.config.Properties.GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES;
import static io.dapr.config.Properties.GRPC_MAX_INBOUND_METADATA_SIZE_BYTES;
import static io.dapr.config.Properties.GRPC_PORT;
import static io.dapr.config.Properties.GRPC_TLS_CA_PATH;
import static io.dapr.config.Properties.GRPC_TLS_CERT_PATH;
import static io.dapr.config.Properties.GRPC_TLS_INSECURE;
import static io.dapr.config.Properties.GRPC_TLS_KEY_PATH;
import static io.dapr.config.Properties.SIDECAR_IP;


/**
* Utility methods for network, internal to Dapr SDK.
*/
Expand Down Expand Up @@ -152,8 +155,11 @@ public static ManagedChannel buildGrpcManagedChannel(Properties properties, Clie
.keepAliveTimeout(settings.keepAliveTimeoutSeconds.toSeconds(), TimeUnit.SECONDS)
.keepAliveWithoutCalls(settings.keepAliveWithoutCalls);
}

return builder.maxInboundMessageSize(settings.maxInboundMessageSize)
.maxInboundMetadataSize(settings.maxInboundMetadataSize)
.build();

return builder.build();
} catch (Exception e) {
throw new DaprException(
new DaprError().setErrorCode("TLS_CREDENTIALS_ERROR")
Expand Down Expand Up @@ -217,7 +223,8 @@ public static ManagedChannel buildGrpcManagedChannel(Properties properties, Clie
.keepAliveWithoutCalls(settings.keepAliveWithoutCalls);
}

return builder.build();
return builder.maxInboundMessageSize(settings.maxInboundMessageSize)
.maxInboundMetadataSize(settings.maxInboundMetadataSize).build();
}

// Not private to allow unit testing
Expand All @@ -233,10 +240,13 @@ static final class GrpcEndpointSettings {
final Duration keepAliveTimeoutSeconds;
final boolean keepAliveWithoutCalls;

final int maxInboundMessageSize;
final int maxInboundMetadataSize;

private GrpcEndpointSettings(
String endpoint, boolean secure, String tlsPrivateKeyPath, String tlsCertPath, String tlsCaPath,
boolean enableKeepAlive, Duration keepAliveTimeSeconds, Duration keepAliveTimeoutSeconds,
boolean keepAliveWithoutCalls) {
boolean keepAliveWithoutCalls, int maxInboundMessageSize, int maxInboundMetadataSize) {
this.endpoint = endpoint;
this.secure = secure;
this.tlsPrivateKeyPath = tlsPrivateKeyPath;
Expand All @@ -246,6 +256,8 @@ private GrpcEndpointSettings(
this.keepAliveTimeSeconds = keepAliveTimeSeconds;
this.keepAliveTimeoutSeconds = keepAliveTimeoutSeconds;
this.keepAliveWithoutCalls = keepAliveWithoutCalls;
this.maxInboundMessageSize = maxInboundMessageSize;
this.maxInboundMetadataSize = maxInboundMetadataSize;
}

static GrpcEndpointSettings parse(Properties properties) {
Expand All @@ -258,6 +270,8 @@ static GrpcEndpointSettings parse(Properties properties) {
Duration keepAliveTimeSeconds = properties.getValue(GRPC_KEEP_ALIVE_TIME_SECONDS);
Duration keepAliveTimeoutSeconds = properties.getValue(GRPC_KEEP_ALIVE_TIMEOUT_SECONDS);
boolean keepAliveWithoutCalls = properties.getValue(GRPC_KEEP_ALIVE_WITHOUT_CALLS);
int maxInboundMessageSizeBytes = properties.getValue(GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES);
int maxInboundMetadataSizeBytes = properties.getValue(GRPC_MAX_INBOUND_METADATA_SIZE_BYTES);

boolean secure = false;
String grpcEndpoint = properties.getValue(GRPC_ENDPOINT);
Expand Down Expand Up @@ -301,27 +315,30 @@ static GrpcEndpointSettings parse(Properties properties) {
address,
port),
secure, clientKeyPath, clientCertPath, caCertPath, enablekeepAlive, keepAliveTimeSeconds,
keepAliveTimeoutSeconds, keepAliveWithoutCalls);
keepAliveTimeoutSeconds, keepAliveWithoutCalls, maxInboundMessageSizeBytes, maxInboundMetadataSizeBytes);
}

var socket = matcher.group("socket");
if (socket != null) {
return new GrpcEndpointSettings(socket, secure, clientKeyPath, clientCertPath, caCertPath, enablekeepAlive,
keepAliveTimeSeconds, keepAliveTimeoutSeconds, keepAliveWithoutCalls);
keepAliveTimeSeconds, keepAliveTimeoutSeconds, keepAliveWithoutCalls,
maxInboundMessageSizeBytes, maxInboundMetadataSizeBytes);
}

var vsocket = matcher.group("vsocket");
if (vsocket != null) {
return new GrpcEndpointSettings(vsocket, secure, clientKeyPath, clientCertPath, caCertPath, enablekeepAlive,
keepAliveTimeSeconds, keepAliveTimeoutSeconds, keepAliveWithoutCalls);
keepAliveTimeSeconds, keepAliveTimeoutSeconds, keepAliveWithoutCalls,
maxInboundMessageSizeBytes, maxInboundMetadataSizeBytes);
}
}

return new GrpcEndpointSettings(String.format(
"dns:///%s:%d",
address,
port), secure, clientKeyPath, clientCertPath, caCertPath, enablekeepAlive, keepAliveTimeSeconds,
keepAliveTimeoutSeconds, keepAliveWithoutCalls);
keepAliveTimeoutSeconds, keepAliveWithoutCalls,
maxInboundMessageSizeBytes, maxInboundMetadataSizeBytes);
}

}
Expand Down
23 changes: 23 additions & 0 deletions sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,27 @@ public void testDefaultKeepAliveOverride() throws Exception {
Assertions.assertEquals(50, settings.keepAliveTimeoutSeconds.getSeconds());
Assertions.assertEquals(false, settings.keepAliveWithoutCalls);
}

@Test
public void testMaxDefaultInboundSize() throws Exception {
Properties properties = new Properties();

GrpcEndpointSettings settings = NetworkUtils.GrpcEndpointSettings.parse(properties);
Assertions.assertEquals(4194304, settings.maxInboundMessageSize);
Assertions.assertEquals(8192, settings.maxInboundMetadataSize);

}

@Test
public void testMaxInboundSize() throws Exception {
Properties properties = new Properties(Map.of(
Properties.GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES.getName(), "123456789",
Properties.GRPC_MAX_INBOUND_METADATA_SIZE_BYTES.getName(), "123456"
));

GrpcEndpointSettings settings = NetworkUtils.GrpcEndpointSettings.parse(properties);
Assertions.assertEquals(123456789, settings.maxInboundMessageSize);
Assertions.assertEquals(123456, settings.maxInboundMetadataSize);

}
}
Loading