-
Notifications
You must be signed in to change notification settings - Fork 248
feat: raise error when advisory lock cannot be acquired within configured timeout #480
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
base: master
Are you sure you want to change the base?
feat: raise error when advisory lock cannot be acquired within configured timeout #480
Conversation
- Add advisory_lock_timeout_seconds option (default: 15 seconds) - Raise error when advisory lock cannot be acquired within timeout - This provides explicit failure behavior for lock contention issues Co-Authored-By: Claude Opus 4.5 <[email protected]>
0eb42a6 to
56a2ea7
Compare
56a2ea7 to
547b422
Compare
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.
Pull request overview
This PR introduces an advisory_lock_timeout_seconds configuration option that allows closure_tree to raise an error when an advisory lock cannot be acquired within a specified timeout period, preventing indefinite blocking and enabling jobs to fail fast and retry during lower contention.
Changes:
- Added
advisory_lock_timeout_secondsconfiguration option with validation - Implemented logic to call
with_advisory_lock!instead ofwith_advisory_lockwhen timeout is configured - Added tests to verify the new timeout functionality
- Updated documentation to describe the new option
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/closure_tree/support.rb | Adds default option, validation logic, and conditional method selection based on timeout configuration |
| lib/closure_tree/support_attributes.rb | Implements advisory_lock_options helper method to build options hash with timeout |
| lib/closure_tree/has_closure_tree.rb | Adds advisory_lock_timeout_seconds to the list of valid configuration keys |
| test/closure_tree/support_test.rb | Adds unit tests for initialization and method selection based on timeout configuration |
| test/closure_tree/parallel_test.rb | Updates stub signature to accept options parameter for backward compatibility |
| README.md | Documents the new advisory_lock_timeout_seconds configuration option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cfe33f5 to
2456d46
Compare
2456d46 to
91c90af
Compare
Overview
This PR introduces an
:advisory_lock_timeout_secondsconfiguration option that triggers an error when an advisory lock cannot be obtained within the specified time limit.Motivation
We experienced jobs that would wait for several minutes executing
SELECT GET_LOCKuntil Sidekiq terminated them. This created queue blockages and led to significant job backlogs. Implementing a timeout enables jobs to fail quickly and retry during periods of lower contention, ultimately completing successfully.Example Usage
Behavior
When
advisory_lock_timeout_secondsis configured, aWithAdvisoryLock::FailedToAcquireLockexception is raised if the lock cannot be secured within the designated timeframe, creating explicit failure handling for lock contention scenarios.Without this configuration, the system maintains the default behavior of waiting indefinitely until lock acquisition.
Implementation Details
advisory_lock_timeout_secondsconfiguration optionwith_advisory_lock!with lock parameters whenadvisory_lock_timeout_secondsis specifiedBackward Compatibility
The
advisory_lock_timeout_secondsoption defaults tonil, andwith_advisory_lock!is only invoked when a non-null value is supplied.