Skip to content

Commit 307bbfd

Browse files
committed
fix: detect shutdown and break DurableTaskGrpcWorker loop
The worker loop ran `while (true)` and only exited if an InterruptedException happened during the 5-second retry sleep. If `close()` was called while the gRPC stream was blocking, the CANCELLED exception was logged but the loop kept retrying. - Replace `while (true)` with a check on `isNormalShutdown` and the thread interrupt flag so the loop exits promptly. - Break out of the retry path on CANCELLED when `isNormalShutdown` is set, avoiding a misleading 5-second sleep after `close()`. - Re-set the interrupt flag before breaking on InterruptedException to preserve the interrupt contract for callers higher up. Signed-off-by: Javier Aliaga <javier@diagrid.io>
1 parent e5cf3f3 commit 307bbfd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void startAndBlock() {
171171
this.dataConverter,
172172
logger);
173173

174-
while (true) {
174+
while (!this.isNormalShutdown && !Thread.currentThread().isInterrupted()) {
175175
try {
176176
OrchestratorService.GetWorkItemsRequest getWorkItemsRequest = OrchestratorService.GetWorkItemsRequest
177177
.newBuilder().build();
@@ -210,6 +210,9 @@ public void startAndBlock() {
210210
this.getSidecarAddress());
211211
} else if (e.getStatus().getCode() == Status.Code.CANCELLED) {
212212
logger.log(Level.INFO, "Durable Task worker has disconnected from {0}.", this.getSidecarAddress());
213+
if (this.isNormalShutdown) {
214+
break;
215+
}
213216
} else {
214217
logger.log(Level.WARNING,
215218
String.format("Unexpected failure connecting to %s", this.getSidecarAddress()), e);
@@ -219,6 +222,7 @@ public void startAndBlock() {
219222
try {
220223
Thread.sleep(5000);
221224
} catch (InterruptedException ex) {
225+
Thread.currentThread().interrupt();
222226
break;
223227
}
224228
}

0 commit comments

Comments
 (0)