fix: guard fcntl.flock(LOCK_UN) in finally blocks against OSError#21719
Closed
vominh1919 wants to merge 1 commit into
Closed
fix: guard fcntl.flock(LOCK_UN) in finally blocks against OSError#21719vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
If fcntl.flock(fd, LOCK_UN) raises OSError in a finally block, the subsequent fd.close() is skipped and the lock is held forever. This affected 6 files across tools/, agent/, hermes_cli/, and cron/. The Windows msvcrt equivalent was already guarded with try/except in all locations — this fix brings the POSIX fcntl path to parity. Files fixed: - tools/skill_usage.py - tools/memory_tool.py - tools/environments/file_sync.py - agent/shell_hooks.py - hermes_cli/auth.py - cron/scheduler.py
Collaborator
Contributor
|
Submitted a fix: #23819 Fixed 5 unguarded |
This was referenced May 11, 2026
Contributor
|
Automated hermes-sweeper review: this fix is already present on current main. Evidence:
Thanks for the report and patch; closing this PR because the requested change has already landed on main. |
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
Six files across the codebase call
fcntl.flock(fd, LOCK_UN)insidefinallyblocks without wrapping it intry/except OSError. If the unlock raises (e.g. the file descriptor was already closed by the OS after a crash, or NFS issues), the exception propagates and skips the subsequentfd.close()— leaving the lock held forever.The Windows
msvcrtequivalent was already guarded withtry/except (OSError, IOError): passin all six locations. This fix brings the POSIXfcntlpath to parity.Fix
Wrap each
fcntl.flock(fd, LOCK_UN)intry/except OSError: passinside thefinallyblocks:tools/skill_usage.pytools/memory_tool.pytools/environments/file_sync.pylock_fd.close()agent/shell_hooks.pyhermes_cli/auth.pycron/scheduler.pylock_fd.close()Pattern
Tests
Each fix is a 3-line addition (
try:,except OSError:,pass) that cannot break existing behavior — it only prevents an exception from propagating. All 6 files pass syntax validation.