fix: guard flock(LOCK_UN) in finally blocks against OSError#16274
Open
vominh1919 wants to merge 1 commit into
Open
fix: guard flock(LOCK_UN) in finally blocks against OSError#16274vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
When fcntl.flock(fd, LOCK_UN) raises OSError in a finally block, the subsequent fd.close() is skipped, leaving the lock file open and the lock held indefinitely. This matches the defensive pattern already used for msvcrt.unlock in the same blocks. Affected modules: - agent/shell_hooks.py: shell hooks allowlist lock - tools/memory_tool.py: memory tool file lock - tools/environments/file_sync.py: sync-back file lock - hermes_cli/auth.py: auth store file lock - cron/scheduler.py: cron tick file lock
Collaborator
This was referenced Apr 30, 2026
This was referenced May 11, 2026
This was referenced May 22, 2026
This was referenced May 30, 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.
Problem
Five
finallyblocks callfcntl.flock(fd, LOCK_UN)without atry/exceptguard. If the unlock raisesOSError(e.g., file descriptor already closed, NFS stale handle, kernel interrupt), the subsequentfd.close()is skipped and the lock file remains open and locked indefinitely.This is the same pattern that was already guarded for
msvcrt(Windows) in every one of these files — but thefcntl(Linux/macOS) path was missed.Affected modules
agent/shell_hooks.pytools/memory_tool.pytools/environments/file_sync.pyhermes_cli/auth.pycron/scheduler.pyFix
Wrap each
fcntl.flock(fd, LOCK_UN)intry/except OSError: pass, matching the defensive pattern already used formsvcrt.unlockin the same blocks.Before vs After