Repository navigation
[runtime][java] Keep worker lock ownership when an async call leaves the interrupt flag set - #1298
Merged
Conversation
…the interrupt flag set Generated-by: Claude Code 2.1.303 (Claude Opus 5.5)
2 tasks done
Contributor
|
Hi @eemario, could you please take a look at this PR? |
Contributor
|
Thanks @sangkyoonnam for the fix and the thorough write-up — clearing the flag once for the re-acquire plus the shutdown-only ownership guard line up with how close() re-issues interrupts, and both the cancellation and the non-shutdown case from #1294 are covered. Verified the focused suites locally on JDK 17 (33/33). LGTM. |
eemario
approved these changes
Oct 21, 2026
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.
Linked issue: #1294
Purpose of change
User-visible outcome
On the JDK < 21 parallel engine, an async call that leaves its worker interrupted keeps its result or original exception if re-acquisition succeeds, and subsequent Action code uses its own runner context. Cancellation no longer produces an uncaught
IllegalStateException: Current thread does not own the lockfrom releasing an unowned lock. The intent is to preserve the call's outcome while keeping shutdown waits interruptible.Runtime flow
executeAsyncand nonemptyexecuteAllAsyncbatches release the parallel lock and re-acquire it infinallythroughreacquireAndRestore. The helper records and clears the existing flag, callsacquireByWorker, restores an initially set flag infinally, and restores runner context only if acquisition succeeds.Work.execute()records action failures instead of throwing them. On return,runOneTaskskipsmarkDone, mailbox completion andreleaseToMainonly when the executor is shut down and the worker lacks ownership. Otherwise scheduling continues.Key decisions
close()repeats once per second during shutdown can end the wait.Behavioral Semantics
Interaction decisions
The table covers lock-backed calls. An interrupted acquisition means
acquireByWorkerthrowsInterruptedException.Behavioral contracts
Failure behavior
Interrupted re-acquisition raises
InterruptedException, replacing the call's outcome; context restoration is skipped.Work.execute()records the failure. During shutdown,runOneTaskabandons the unowned task. Outside shutdown, the existing ownership checks still fail. Call failures otherwise propagate after successful re-acquisition and restoration; restoration failures still propagate.Tests
ContinuationActionExecutorTest.executeAsyncKeepsResultWhenCallLeavesInterruptFlagSetContinuationActionExecutorTest.executeAsyncKeepsFailureWhenCallLeavesInterruptFlagSetParallelExecutionCoordinatorTest.shutdownDuringAsyncReacquireAbandonsTaskWithoutLockErrorsCoverage targets outcome preservation, interrupt visibility and clean cancellation. A Java chat-call cancellation check on Flink 2.3.0 also showed no ownership error.
Not verified:
executeAllAsyncspecifically.Ownership invariants and supporting test evidence
releaseToMain.FakeWorkthat returns without ownership after interrupted re-acquisition; it asserts no commit, mailbox failure or uncaught error.ContinuationActionExecutorTest,ParallelExecutionCoordinatorTestandParallelExecutionLockTest. JDK 11/17: 33 tests pass; JDK 21: 27 pass and all 6 executor tests are skipped because they require the JDK < 21 implementation.mvn -pl runtime testpasses on JDK 17 (1355 tests) and JDK 21 (1365).WorkflowSingleAgentExample, cancellation with a pending chat request:CANCELED, no lock-ownership or uncaught error.API
Public signatures are unchanged. Existing JDK < 21 parallel callers retain outcomes when an existing interrupt flag previously caused re-acquisition to fail. JDK 21+ and execution without the parallel lock are unchanged.
ParallelExecutionLock.isHeldByCurrentThread()is package-private.Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 2.1.303 (Claude Opus 5.5)