-
Notifications
You must be signed in to change notification settings - Fork 25
Unlock files when any Exception is raised. #1288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsure file locks are always released safely by only unlocking when a lock is still held and by unlocking on any unexpected exception, not just address-in-use errors. Sequence diagram for lock handling on exceptionssequenceDiagram
participant Caller
participant inner
participant LockManager
participant ActiveLock
Caller->>inner: call inner(args, kwargs)
loop retry_until_locked
inner->>LockManager: attempt_lock()
alt lock_acquired
LockManager-->>inner: lock_success = True
inner->>ActiveLock: perform_operation_with_lock()
Note over inner,ActiveLock: (implicit work, not shown in code)
inner->>ActiveLock: unlock_if_locked()
ActiveLock-->>inner: lock_released
inner-->>Caller: return result
else AddressAlreadyInUse
LockManager-->>inner: raise AddressAlreadyInUse
inner->>ActiveLock: if locked then unlock()
ActiveLock-->>inner: lock_released
Note over inner,LockManager: lock_success = False, retry loop
else other_Exception
LockManager-->>inner: raise Exception
inner->>ActiveLock: if locked then unlock()
ActiveLock-->>inner: lock_released
inner-->>Caller: re_raise_exception
end
end
Flow diagram for conditional lock unlocking on exceptionsflowchart TD
A[start inner] --> B[attempt to acquire locks]
B --> C{exception raised?}
C -->|no| D[set lock_success based on acquisition]
C -->|AddressAlreadyInUse| E[set lock_success to False]
C -->|other Exception| F[set lock_success to False]
E --> G[for each active_lock<br/>if active_lock.locked<br/>unlock]
F --> H[for each active_lock<br/>if active_lock.locked<br/>unlock]
H --> I[re_raise exception]
D --> J{lock_success is True?}
J -->|yes| K[for each active_lock<br/>if active_lock.locked<br/>unlock]
J -->|no| L[retry loop or exit]
K --> M[return result]
L --> N[end inner]
I --> N
M --> N
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The unlocking logic for
currently_active_locksis now duplicated in theAddressAlreadyInUsehandler, the genericExceptionhandler, and thefinallyblock; consider extracting this into a small helper or shared block to avoid divergence in future changes. - Catching a broad
Exceptionand immediately re-raising is reasonable for cleanup, but you might want to narrow this to a more specific base class (e.g.OSError-related) if only operational errors are expected here, to avoid unexpected interactions with unrelated exceptions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The unlocking logic for `currently_active_locks` is now duplicated in the `AddressAlreadyInUse` handler, the generic `Exception` handler, and the `finally` block; consider extracting this into a small helper or shared block to avoid divergence in future changes.
- Catching a broad `Exception` and immediately re-raising is reasonable for cleanup, but you might want to narrow this to a more specific base class (e.g. `OSError`-related) if only operational errors are expected here, to avoid unexpected interactions with unrelated exceptions.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
4657c43 to
43e1d9a
Compare
[CLOUDDST-30851]
JAVGan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[CLOUDDST-30851]
Summary by Sourcery
Bug Fixes: