Skip to content

Conversation

@slfan1989
Copy link
Contributor

@slfan1989 slfan1989 commented Feb 10, 2026

What changes were proposed in this pull request?

Add client-side message size validation for async requests to fail fast before sending oversized messages over the network.

Currently, async requests are only validated on the server side, causing  unnecessary network overhead. This change adds early validation in  GrpcClientProtocolClient.asyncSend() to match the existing behavior 
in the sync path (GrpcClientRpc).

What is the link to the Apache JIRA

RATIS-2404. Validate message size before sending async requests.

How was this patch tested?

Add Junit Test.

@slfan1989
Copy link
Contributor Author

@szetszwo Could you please review this PR? Thank you very much!

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slfan1989 , thanks a lot for working on this!

Please see the comments inlined and also https://issues.apache.org/jira/secure/attachment/13080732/1345_review.patch

private final ManagedChannel clientChannel;
private final ManagedChannel adminChannel;

private final int maxMessageSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use SizeInBytes. The String will look when printing it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let’s use SizeInBytes. The string representation should be fine when we print it out.


private ManagedChannel buildChannel(String address, SslContext sslContext,
SizeInBytes flowControlWindow, SizeInBytes maxMessageSize) {
SizeInBytes flowControlWindow, SizeInBytes maxMessageSizeConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it becomes a field, let's remove the parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — I’ll remove the parameter since it’s now a field.

}
final RaftClientRequestProto proto;
try {
proto = toRaftClientRequestProto(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea to validate to request first. Let's check it in the very beginning of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review patch — I’ve already updated and improved the code accordingly.

Comment on lines 244 to 245
throw new IOException(getName() + ": Message size:" + proto.getSerializedSize()
+ " exceeds maximum:" + maxMessageSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Use IllegalArgumentException
  • Use "request serialized size" instead of "Message size"
  • Include the request.

Comment on lines 240 to 242
private RaftClientRequestProto toRaftClientRequestProto(RaftClientRequest request) throws IOException {
return ClientProtoUtils.toRaftClientRequestProto(request);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slfan1989 , thanks for update!

Please remove this method and use ClientProtoUtils.toRaftClientRequestProto(..) directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestions—I’ve updated and improved the code.

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo szetszwo merged commit 563db23 into apache:master Feb 11, 2026
16 checks passed
@slfan1989
Copy link
Contributor Author

+1 the change looks good.

@szetszwo Thank you so much for reviewing the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants