Skip to content

Commit f5fe52e

Browse files
committed
fix: accept workflow work items larger than gRPC's 4MB default (#1860)
The workflow runtime builds its sidecar channel with the SDK's inbound message limit, dapr.grpc.max.inbound.message.size.bytes, which defaults to 4MB. The sidecar sends work items up to its own max body size, which apps raise for large payloads, so a work item over 4MB (for example a fan-out of five 1MB activity results) failed the GetWorkItems stream with RESOURCE_EXHAUSTED. The worker reconnected, the sidecar redelivered the same work item, and it failed again, so every workflow on the worker stalled. The history fetch after a stateful history cache miss had the same limit. Signed-off-by: joshvanl <me@joshvanl.dev> (cherry picked from commit ae6016d) Signed-off-by: joshvanl <me@joshvanl.dev>
1 parent e53f859 commit f5fe52e

2 files changed

Lines changed: 138 additions & 1 deletion

File tree

‎durabletask-client/src/main/java/io/dapr/durabletask/DurableTaskGrpcWorker.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public final class DurableTaskGrpcWorker implements AutoCloseable {
101101

102102
this.tracer = GlobalOpenTelemetry.getTracer("dapr-workflow");
103103

104-
this.sidecarClient = TaskHubSidecarServiceGrpc.newBlockingStub(sidecarGrpcChannel);
104+
// The sidecar bounds work items and histories by its max request body size. A lower receive
105+
// limit here only makes the worker refuse, re-fetch and refuse the same work item forever.
106+
this.sidecarClient = TaskHubSidecarServiceGrpc.newBlockingStub(sidecarGrpcChannel)
107+
.withMaxInboundMessageSize(Integer.MAX_VALUE);
105108
this.dataConverter = builder.dataConverter != null ? builder.dataConverter : new JacksonDataConverter();
106109
this.maximumTimerInterval = builder.maximumTimerInterval != null ? builder.maximumTimerInterval
107110
: DEFAULT_MAXIMUM_TIMER_INTERVAL;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright 2026 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
package io.dapr.durabletask;
15+
16+
import com.google.protobuf.StringValue;
17+
import io.dapr.durabletask.implementation.protobuf.Orchestration;
18+
import io.dapr.durabletask.implementation.protobuf.OrchestratorService;
19+
import io.dapr.durabletask.implementation.protobuf.TaskHubSidecarServiceGrpc;
20+
import io.grpc.ManagedChannel;
21+
import io.grpc.ManagedChannelBuilder;
22+
import io.grpc.Server;
23+
import io.grpc.netty.NettyServerBuilder;
24+
import io.grpc.stub.StreamObserver;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.Test;
27+
28+
import java.util.concurrent.CompletableFuture;
29+
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.TimeoutException;
31+
import java.util.concurrent.atomic.AtomicInteger;
32+
33+
import static org.junit.jupiter.api.Assertions.assertEquals;
34+
35+
/**
36+
* Verifies DurableTaskGrpcWorker accepts a work item larger than gRPC's 4MB default receive limit.
37+
*
38+
* <p>daprd sends work items up to its own max body size, so a fan-out of five 1MB activity results
39+
* is a work item of about 6MB. The channel is built like the SDK's own, whose inbound limit defaults
40+
* to 4MB (DAPR_GRPC_MAX_INBOUND_MESSAGE_SIZE_BYTES). Uses a real TCP server because the in-process
41+
* transport does not enforce message sizes.</p>
42+
*/
43+
class DurableTaskGrpcWorkerLargeWorkItemTest {
44+
45+
private static final int DEFAULT_MAX_INBOUND_BYTES = 4 * 1024 * 1024;
46+
private static final int PAYLOAD_CHARS = 6 * 1024 * 1024;
47+
private static final String ACTIVITY_NAME = "PayloadLength";
48+
49+
private DurableTaskGrpcWorker worker;
50+
private ManagedChannel channel;
51+
private Server server;
52+
53+
@AfterEach
54+
void tearDown() throws Exception {
55+
if (worker != null) {
56+
worker.close();
57+
}
58+
if (channel != null) {
59+
channel.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
60+
}
61+
if (server != null) {
62+
server.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
63+
}
64+
}
65+
66+
@Test
67+
void workerProcessesWorkItemLargerThanDefaultReceiveLimit() throws Exception {
68+
OrchestratorService.ActivityRequest activityRequest = OrchestratorService.ActivityRequest.newBuilder()
69+
.setName(ACTIVITY_NAME)
70+
.setTaskId(1)
71+
.setWorkflowInstance(Orchestration.WorkflowInstance.newBuilder().setInstanceId("instance").build())
72+
.setInput(StringValue.of("\"" + "x".repeat(PAYLOAD_CHARS) + "\""))
73+
.build();
74+
OrchestratorService.WorkItem workItem = OrchestratorService.WorkItem.newBuilder()
75+
.setActivityRequest(activityRequest)
76+
.build();
77+
78+
AtomicInteger streams = new AtomicInteger();
79+
CompletableFuture<OrchestratorService.ActivityResponse> activityResponse = new CompletableFuture<>();
80+
server = NettyServerBuilder.forPort(0)
81+
.addService(new TaskHubSidecarServiceGrpc.TaskHubSidecarServiceImplBase() {
82+
@Override
83+
public void getWorkItems(
84+
OrchestratorService.GetWorkItemsRequest request,
85+
StreamObserver<OrchestratorService.WorkItem> responseObserver) {
86+
streams.incrementAndGet();
87+
if (!activityResponse.isDone()) {
88+
responseObserver.onNext(workItem);
89+
}
90+
// Hold the stream open, as daprd does.
91+
}
92+
93+
@Override
94+
public void completeActivityTask(
95+
OrchestratorService.ActivityResponse request,
96+
StreamObserver<OrchestratorService.CompleteTaskResponse> responseObserver) {
97+
activityResponse.complete(request);
98+
responseObserver.onNext(OrchestratorService.CompleteTaskResponse.getDefaultInstance());
99+
responseObserver.onCompleted();
100+
}
101+
})
102+
.build()
103+
.start();
104+
105+
channel = ManagedChannelBuilder.forAddress("localhost", server.getPort())
106+
.usePlaintext()
107+
.maxInboundMessageSize(DEFAULT_MAX_INBOUND_BYTES)
108+
.build();
109+
worker = new DurableTaskGrpcWorkerBuilder()
110+
.grpcChannel(channel)
111+
.addActivity(new TaskActivityFactory() {
112+
@Override
113+
public String getName() {
114+
return ACTIVITY_NAME;
115+
}
116+
117+
@Override
118+
public TaskActivity create() {
119+
return ctx -> ctx.getInput(String.class).length();
120+
}
121+
})
122+
.build();
123+
worker.start();
124+
125+
OrchestratorService.ActivityResponse result;
126+
try {
127+
result = activityResponse.get(15, TimeUnit.SECONDS);
128+
} catch (TimeoutException e) {
129+
throw new AssertionError("no activity result after " + streams.get() + " work item streams: "
130+
+ "the worker could not receive the work item", e);
131+
}
132+
assertEquals(String.valueOf(PAYLOAD_CHARS), result.getResult().getValue());
133+
}
134+
}

0 commit comments

Comments
 (0)