Report Activity result when the Activity leaves the interrupt flag set - #3000
Open
samarth70 wants to merge 1 commit into
Open
Report Activity result when the Activity leaves the interrupt flag set#3000samarth70 wants to merge 1 commit into
samarth70 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
ActivityWorkernow 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 whenThread.interrupted()is set (io.grpc.stub.ClientCalls#blockingUnaryCall), which the SDK already notes inMultiThreadedPoller.PollTask. So theRespondActivityTaskCompletedcall 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":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
finallyonce reporting is done, so it still reaches the thread pool and continues to work for shutdown, per the approach suggested in the issue.Checklist
Closes Activities that return with interrupted flag should be successfully reported as Completed #731
How was this tested:
Added
io.temporal.activity.ActivityInterruptedFlagTestwith two cases matching the two scenarios described in the issue: an Activity that never noticed the flag, and one that caught anInterruptedException, 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 withActivity task timed outas above) and pass with this change../gradlew :temporal-sdk:test --tests "io.temporal.activity.ActivityInterruptedFlagTest"reportstests="2" failures="0" errors="0", and:temporal-sdk:spotlessCheckpasses.No.