[Forked] [SPARK-53394][CORE] UninterruptibleLock.isInterruptible should avoid duplicated interrupt #5
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.
Original Description:
What changes were proposed in this pull request?
This PR fixes
UninterruptibleLock.isInterruptibleto avoid duplicated interruption when the thread is already interrupted.Why are the changes needed?
The "uninterruptible" semantic of
UninterruptibleThreadis broken (i.e.,UninterruptibleThreadis interruptible even if it's underrunUninterruptibly) after the fix apache#50594. The probelm is that the state ofshouldInterruptThreadbecomes unsafe when there are multiple interrupts concurrently.For example, thread A could interrupt UninterruptibleThread ut first before UninterruptibleThread enters
runUninterruptibly. Right after that, another thread B starts to invoke ut.interrupt() and pass throughuninterruptibleLock.isInterruptible(becasue at this point,shouldInterruptThread = uninterruptible = false). Before thread B invokessuper.interrupt(), UninterruptibleThread ut entersrunUninterruptiblyand pass throughuninterruptibleLock.getAndSetUninterruptibleand setuninterruptible = true. Then, thread ut continues the checkuninterruptibleLock.isInterruptPending. However,uninterruptibleLock.isInterruptPendingreturn false at this point (due toshouldInterruptThread = Thread.interrupted = true) even though thread B is actully interrupting. As a result, the state ofshouldInterruptThreadbecomes inconsistent between thread B and thread ut. Then, asuninterruptibleLock.isInterruptPendingreturns false, ut to continute to executef. At the same time, thread B invokessuper.interrupt(), andfcould be interruptedDoes this PR introduce any user-facing change?
No.
How was this patch tested?
Manually tested. The issue can be easily reproduced if we run
UninterruptibleThreadSuite.stress testfor 100 times in a row:And the issue is gone after the fix.
Was this patch authored or co-authored using generative AI tooling?
No
Original Author: Ngone51