Skip to content

Harden NXLock release and construction - #273

Merged
rayosborn merged 1 commit into
nexpy:mainfrom
rayosborn:harden-nxlock
Oct 2, 2026
Merged

rayosborn merged 1 commit into
nexpy:mainfrom
rayosborn:harden-nxlock

Conversation

@rayosborn

Copy link
Copy Markdown
Contributor

Summary

  • release() now guards os.close, so the lock file is always removed and fd reset even if closing fails
  • fd is set before anything in __init__ can raise, so __del__ no longer hits an AttributeError after an invalid lock directory
  • __enter__ returns the lock, so with NXLock(f) as lock binds it instead of None
  • Polling in acquire() and wait() sleeps at least 0.1 s, so check_interval=0 cannot busy-wait
  • Corrected the lock_file/fd and is_stale docstrings

Tests

  • Added a test for a failed constructor followed by release(), and a test for the context-manager return value
  • The removal-error tests now undo their patch and clear the lock, so they no longer leave files in a configured lock directory

🤖 Generated with Claude Code

- Guard os.close in release() so the lock file is always removed and fd reset
- Initialize fd before any exception can be raised in __init__, so __del__
  is safe after an invalid lock directory
- Return the lock from __enter__ so `with NXLock(f) as lock` binds it
- Enforce a minimum 0.1 s polling interval to avoid busy-waiting
- Correct the lock_file/fd and is_stale docstrings
- Add tests for the constructor failure and context manager; clean up locks
  left behind by the removal-error tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rayosborn
rayosborn merged commit c18fd2b into nexpy:main Oct 2, 2026
16 checks passed
@rayosborn
rayosborn deleted the harden-nxlock branch October 2, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant