Skip to content

[cpp_extension] Replace FileBaton with filelock to fix stale-lock deadlock - #190543

Closed
malfet wants to merge 1 commit into
gh/malfet/985/basefrom
gh/malfet/985/head
Closed

malfet wants to merge 1 commit into
gh/malfet/985/basefrom
gh/malfet/985/head

Conversation

@malfet

@malfet malfet commented Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes #189245

Test Plan:

python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 [email protected]

cc @janeyx99

[ghstack-poisoned]
@malfet
malfet requested review from ezyang and fmassa as code owners July 20, 2026 13:44
@pytorch-bot

pytorch-bot Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190543

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d4571d2 with merge base 63d4ffc (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

malfet added a commit that referenced this pull request Jul 20, 2026
…dlock

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes #189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>
ghstack-source-id: 14cb2ba
Pull-Request: #190543
@ezyang

ezyang commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 20, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@Skylion007 Skylion007 added module: cpp-extensions Related to torch.utils.cpp_extension release notes: cpp release notes category labels Jul 20, 2026
@Skylion007

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

zjliu-amd pushed a commit to zjliu-amd/pytorch that referenced this pull request Jul 21, 2026
…dlock (pytorch#190543)

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes pytorch#189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Pull Request resolved: pytorch#190543
Approved by: https://github.com/ezyang, https://github.com/Skylion007
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…dlock (pytorch#190543)

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes pytorch#189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Pull Request resolved: pytorch#190543
Approved by: https://github.com/ezyang, https://github.com/Skylion007
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…dlock (pytorch#190543)

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes pytorch#189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Pull Request resolved: pytorch#190543
Approved by: https://github.com/ezyang, https://github.com/Skylion007
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…dlock (pytorch#190543)

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes pytorch#189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Pull Request resolved: pytorch#190543
Approved by: https://github.com/ezyang, https://github.com/Skylion007
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…dlock (pytorch#190543)

FileBaton.try_acquire() creates a lock file and only removes it in a
finally, so a builder killed by SIGKILL/OOM/Slurm leaves the file behind
and every later load() spins forever in FileBaton.wait(). Replace it with
a blocking torch.utils._filelock.FileLock (an OS-level flock), which the
kernel releases when the holder dies. The build now runs inside the lock
with the version re-check, so a crashed build is retried instead of
leaving waiters to load a partial module. FileBaton is kept for BC.

Fixes pytorch#189245

Test Plan:

  python test/test_cpp_extensions_jit.py -k stale_lock

Co-Authored-By: Claude Opus 4.8 <[email protected]>

Pull Request resolved: pytorch#190543
Approved by: https://github.com/ezyang, https://github.com/Skylion007
@github-actions
github-actions Bot deleted the gh/malfet/985/head branch August 20, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: cpp-extensions Related to torch.utils.cpp_extension open source release notes: cpp release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants