Skip to content

Report Activity result when the Activity leaves the interrupt flag set - #3000

Open
samarth70 wants to merge 1 commit into
temporalio:mainfrom
samarth70:fix/report-activity-result-with-interrupted-flag
Open

Report Activity result when the Activity leaves the interrupt flag set#3000
samarth70 wants to merge 1 commit into
temporalio:mainfrom
samarth70:fix/report-activity-result-with-interrupted-flag

Conversation

@samarth70

Copy link
Copy Markdown

What was changed

ActivityWorker now clears the thread's interrupt flag around the call that reports an Activity result, and restores it afterwards.

Why

An Activity can return with the interrupt flag raised, either because it caught an InterruptedException, restored the flag and carried on, or because it never noticed the flag at all. gRPC's blocking stubs abort when Thread.interrupted() is set (io.grpc.stub.ClientCalls#blockingUnaryCall), which the SDK already notes in MultiThreadedPoller.PollTask. So the RespondActivityTaskCompleted call issued immediately after the Activity returns fails, and the result is never reported. The Activity then times out and the Workflow observes a failure even though the Activity completed successfully.

Reproduced on main (v1.38.0) with an Activity that raises the flag and returns "done":

WARN  i.t.internal.worker.ActivityWorker - Failure during reporting of activity result
	at io.temporal.internal.worker.ActivityWorker$TaskHandlerImpl.sendReply(ActivityWorker.java:406)
	at io.temporal.internal.worker.ActivityWorker$TaskHandlerImpl.handleActivity(ActivityWorker.java:357)
...
io.temporal.failure.ActivityFailure: Activity with activityType='Execute' failed: 'Activity task timed out'

This is the general case of the problem fixed for one specific caller in #722; that PR removed an interrupt the SDK itself was raising, while this makes the reporting path resilient to a flag raised by user code.

The flag is restored in a finally once reporting is done, so it still reaches the thread pool and continues to work for shutdown, per the approach suggested in the issue.

Checklist

  1. Closes Activities that return with interrupted flag should be successfully reported as Completed #731

  2. How was this tested:

Added io.temporal.activity.ActivityInterruptedFlagTest with two cases matching the two scenarios described in the issue: an Activity that never noticed the flag, and one that caught an InterruptedException, restored the flag and returned a result. Both assert the Workflow receives the Activity's return value.

Both fail on unmodified main (the Workflow fails with Activity task timed out as above) and pass with this change. ./gradlew :temporal-sdk:test --tests "io.temporal.activity.ActivityInterruptedFlagTest" reports tests="2" failures="0" errors="0", and :temporal-sdk:spotlessCheck passes.

  1. Any docs updates needed?

No.

An Activity can return with the thread's interrupt flag raised, either
because it caught an InterruptedException and restored the flag or
because it never noticed the flag at all. gRPC's blocking stubs abort
when Thread.interrupted() is set, so the RespondActivityTaskCompleted
call made right after the Activity returned failed and the result was
never reported. The Activity then timed out and the workflow saw a
failure even though the Activity had completed successfully.

Clear the flag around the reporting call and restore it afterwards, so
the result reaches the server and the flag still reaches the thread
pool.

Fixes temporalio#731
@samarth70
samarth70 requested a review from a team as a code owner August 11, 2026 19:37
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.

Activities that return with interrupted flag should be successfully reported as Completed

1 participant