Fix a blocking-pool deadlock in nativelink_util::fs::read_dir [1.6-patch-5] - #2647
Open
cormacrelf wants to merge 3 commits into
Open
Fix a blocking-pool deadlock in nativelink_util::fs::read_dir [1.6-patch-5]#2647cormacrelf wants to merge 3 commits into
nativelink_util::fs::read_dir [1.6-patch-5]#2647cormacrelf wants to merge 3 commits into
Conversation
…wn_blocking I believe this may have caused deadlock on actions with a lot of inputs (700+)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Description
The previous implementation acquired a blocking-pool permit and then, from inside that blocking-pool thread, called
Handle::current().block_on(tokio::fs::read_dir(path)). Buttokio::fs::read_diris itself implemented as aspawn_blocking, so this nestedblock_onrequired a second blocking-pool thread to be available to make progress — every call toread_dirneeded two pool threads at once instead of one.Under enough concurrent callers (e.g.
upload_directory's unbounded directory-tree fan-out on an action with many inputs), all blocking-pool threads could end up parked waiting on inner tasks that could never get a thread to run on, freezing everyfs::operation in the process. I believe this may have caused deadlocks on actions with a lot of inputs (700+).Fix: acquire the permit, then simply
.awaittokio::fs::read_dirdirectly instead ofblock_on-ing it — no nested blocking-pool thread is required.Type of change
How Has This Been Tested?
New regression test
read_dir_needs_only_one_blocking_threadinnativelink-util/tests/fs_test.rs: builds a runtime withmax_blocking_threads(1)and assertsfs::read_dircompletes within a 5s timeout. The pre-fix implementation deadlocks in this configuration since it requires two blocking-pool threads at once.Checklist
bazel test //...passes locallygit amendsee some docsThis change is