-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50768][CORE] Introduce TaskContext.createResourceUninterruptib…
…ly to avoid stream leak by task interruption ### What changes were proposed in this pull request? This PR fixes the potential stream leak issue by introduing `TaskContext.createResourceUninterruptibly`. When a task is using `TaskContext.createResourceUninterruptibly` to create the resource, the task would be marked as uninterruptible. Thus, any interruption request during the call to `TaskContext.createResourceUninterruptibly` would be delayed until the creation finishes. This PR introduces an new lock contention between `Task.kill` and `TaskContext.createResourceUninterruptibly`. But I think it is acceptable given that both are not on the hot-path. (I will submmit a followup to apply `TaskContext.createResourceUninterruptibly` in the codebase if this PR is approved by the community.) ### Why are the changes needed? We had #48483 tried to fix the potential stream leak issue by task interruption. It mitigates the issue by using ```scala def tryInitializeResource[R <: Closeable, T](createResource: => R)(initialize: R => T): T = { val resource = createResource try { initialize(resource) } catch { case e: Throwable => resource.close() throw e } } ``` But this utility function has an issue that `resource.close()` would leak open resouces if `initialize(resource)` also created some resources internally, especially when `initialize(resource)` is interrupted (See the example of `InterruptionSensitiveInputStream` in the test). ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added a unit test. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #49413 from Ngone51/dev-interrupt. Authored-by: Yi Wu <[email protected]> Signed-off-by: yangjie01 <[email protected]>
- Loading branch information
1 parent
f223b8d
commit 6f3b778
Showing
6 changed files
with
235 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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