Skip to content

Commit 3b22a86

Browse files
committed
The test failed with "too many messages" error due to sending an empty body message to the data plane server during the "half-close" phase . For a unary RPC, this was interpreted as a second request message, which is invalid. I've updated handleRequestBodyResponse and onExternalBody to only call super.sendMessage() or super.onMessage() if the body content is non-empty. This prevents the redundant empty message from being sent to the data plane while still allowing the external processor to signal the end of the stream.
1 parent 06c0f8c commit 3b22a86

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

xds/src/main/java/io/grpc/xds/ExternalProcessorFilter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,10 @@ private void handleRequestBodyResponse(io.envoyproxy.envoy.service.ext_proc.v3.B
549549
io.envoyproxy.envoy.service.ext_proc.v3.BodyMutation mutation = bodyResponse.getResponse().getBodyMutation();
550550
if (mutation.hasBody()) {
551551
byte[] mutatedBody = mutation.getBody().toByteArray();
552-
super.sendMessage(new ByteArrayInputStream(mutatedBody));
552+
if (mutatedBody.length > 0) {
553+
super.sendMessage(new ByteArrayInputStream(mutatedBody));
554+
}
553555
} else if (mutation.getClearBody()) {
554-
// "clear_body" means we should send an empty message.
555556
super.sendMessage(new ByteArrayInputStream(new byte[0]));
556557
}
557558
// If body mutation is present but has no body and clear_body is false, do nothing.
@@ -718,7 +719,9 @@ void proceedWithClose() {
718719
}
719720

720721
void onExternalBody(com.google.protobuf.ByteString body) {
721-
super.onMessage(body.newInput());
722+
if (body.size() > 0) {
723+
super.onMessage(body.newInput());
724+
}
722725
}
723726

724727
void unblockAfterStreamComplete() {

xds/src/test/java/io/grpc/xds/ExternalProcessorFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void requestHeadersMutated() throws Exception {
168168
ExternalProcessorFilterConfig filterConfig = createFilterConfig();
169169

170170
// Manually create the interceptor using the test-friendly constructor
171-
CachedChannelManager testChannelManager = new CachedChannelManager(config ->
171+
CachedChannelManager testChannelManager = new CachedChannelManager(config ->
172172
grpcCleanup.register(InProcessChannelBuilder.forName(extProcServerName).directExecutor().build())
173173
);
174174
ClientInterceptor interceptor = new ExternalProcessorInterceptor(filterConfig, testChannelManager);

0 commit comments

Comments
 (0)