Suppress ValueError in _try_break_stale_lock for corrupted lock files#496
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Feb 21, 2026
Merged
Conversation
The suppress(OSError) context manager doesn't catch ValueError, which is raised by int(pid_str) when the lock file content is corrupted or contains non-numeric data on the PID line. This crashes the lock acquisition instead of gracefully skipping the stale lock check. A corrupted lock file should be treated the same as any other unreadable lock file — the stale lock check should be skipped and acquisition should proceed normally.
gaborbernat
approved these changes
Feb 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.
SoftFileLock._try_break_stale_lock()wraps its body insuppress(OSError)to handle I/O errors gracefully. However, if the lock file content is corrupted (e.g. non-numeric PID line),int(pid_str)raisesValueErrorwhich is not suppressed, crashing the lock acquisition.This can happen when:
The fix adds
ValueErrorto thesuppress()call, so corrupted lock files are treated the same as unreadable ones — the stale lock check is skipped and acquisition proceeds normally.