Skip to content

Commit 8544c12

Browse files
committed
Fix activity completion when thread interrupted flag is set
1 parent 140980e commit 8544c12

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

temporal-sdk/src/main/java/io/temporal/internal/worker/ActivityWorker.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,9 @@ public Throwable wrapFailure(ActivityTask t, Throwable failure) {
347347
*/
348348
private void executeGrpcCallWithInterruptHandling(Runnable grpcCall) {
349349
// Check if the current thread is interrupted before making gRPC calls
350-
// If it is, we need to temporarily clear the flag to allow gRPC calls to succeed,
351-
// then restore it after reporting. This handles the case where an activity
352-
// catches InterruptedException, restores the interrupted flag, and continues to return a
353-
// result.
350+
// If it is, we need to temporarily clear the flag to allow gRPC calls to succeed,then restore it after reporting.
351+
// This handles the case where an activity catches InterruptedException, restores the interrupted flag,
352+
// and continues to return a result.
354353
// See: https://github.com/temporalio/sdk-java/issues/731
355354
boolean wasInterrupted = Thread.interrupted(); // This clears the flag
356355
try {

temporal-sdk/src/test/java/io/temporal/worker/InterruptedActivityCompletionValidationTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
/**
2525
* Validation test for the interrupted activity completion fix.
2626
*
27-
* <p>This test demonstrates that the fix for https://github.com/temporalio/sdk-java/issues/731 is
28-
* working correctly. Before the fix, activities that returned with the interrupted flag set would
29-
* fail to report their results due to gRPC call failures.
27+
* <p>This test demonstrates that the fix for https://github.com/temporalio/sdk-java/issues/731 is working correctly.
28+
* Before the fix, activities that returned with the interrupted flag set would fail to report their results
29+
* due to gRPC call failures.
3030
*
31-
* <p>The fix was applied in ActivityWorker.sendReply() method to temporarily clear the interrupted
32-
* flag during gRPC calls and restore it afterward.
31+
* <p>The fix was applied in ActivityWorker.sendReply() method to temporarily clear the interrupted flag
32+
* during gRPC calls and restore it afterward.
3333
*/
3434
public class InterruptedActivityCompletionValidationTest {
3535

@@ -59,9 +59,11 @@ public interface TestActivity {
5959
/**
6060
* This test validates that the fix is working by demonstrating that:
6161
*
62-
* <p>1. An activity can set the interrupted flag and still return a result 2. The result is
63-
* successfully reported to the Temporal server 3. The workflow completes with the expected result
64-
* 4. The activity completion is properly recorded in the workflow history
62+
* <p>
63+
* 1. An activity can set the interrupted flag and still return a result
64+
* 2. The result is successfully reported to the Temporal server
65+
* 3. The workflow completes with the expected result
66+
* 4. The activity completion is properly recorded in the workflow history
6567
*
6668
* <p>Before the fix: This test would fail with CancellationException during gRPC calls After the
6769
* fix: This test passes, proving activities can complete despite interrupted flag

0 commit comments

Comments
 (0)