Release file locks on close failure and clarify path errors#265
Merged
Conversation
NeXusError messages for invalid indices and invalid paths in NXgroup now interpolate the key or resolved path, so the caller can see which lookup failed instead of just "Invalid path" / "Invalid index". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
NXFile.close() called release_lock() unconditionally only if the preceding self._file.close() did not raise; a flush error during close would therefore strand the .lock file on disk and block every subsequent acquire until the 8-hour expiry kicked in. NXFile.__exit__ had the same shape: a raising close() left _with_count stuck at 1, so later with-blocks on the same NXFile would skip open() entirely and never retry the close. Wrap both in try/finally so the lock is always released and the counter always decrements. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Two unrelated fixes bundled together.
Release file lock even if h5py close raises
NXFile.close()previously calledrelease_lock()only if the precedingself._file.close()did not raise. An h5py flush error during close would therefore strand the.lockfile on disk, blocking every subsequentacquire_lock()on the same file until the 8-hourexpirywindow kicked in.NXFile.__exit__had the same shape: a raisingclose()left_with_countstuck at 1, so laterwith-blocks on the same NXFile skippedopen()entirely and never retried the close.Both are now wrapped in
try/finallyso the lock is always released and the counter always decrements. This was surfaced by annxrefineworkflow where a failednxlinktask left a stale.lockfile behind, and subsequentnxmaxruns on sibling entries blocked indefinitely onacquire_lock().Include the offending key in NXgroup path-error messages
NXgroup.__getitem__and__setitem__raisedNeXusError("Invalid index")/NeXusError("Invalid path")with no indication of which key triggered the failure. The messages now interpolate the offending key or resolved path so the caller can tell at a glance which lookup went wrong.Test plan
with nxopen(file, 'rw'):block and confirm the.lockfile is removed and_with_countreturns to 0withblock after a simulated close failure and confirm it acquires the lock cleanly rather than skippingopen()NeXusErrorfromNXgroup['/nonexistent/path']and confirm the message includes the path