Skip to content

Conversation

@Farjaad
Copy link

@Farjaad Farjaad commented Jan 28, 2026

Overview

This PR introduces an :advisory_lock_timeout_seconds configuration 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_LOCK until 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

class Tag < ApplicationRecord
  has_closure_tree advisory_lock_timeout_seconds: 30
end

Behavior

When advisory_lock_timeout_seconds is configured, a WithAdvisoryLock::FailedToAcquireLock exception 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

  • Introduces advisory_lock_timeout_seconds configuration option
  • Invokes with_advisory_lock! with lock parameters when advisory_lock_timeout_seconds is specified

Backward Compatibility

The advisory_lock_timeout_seconds option defaults to nil, and with_advisory_lock! is only invoked when a non-null value is supplied.

- 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 <noreply@anthropic.com>
@Farjaad Farjaad force-pushed the advisory-lock-timeout-seconds branch 6 times, most recently from 0eb42a6 to 56a2ea7 Compare January 28, 2026 21:17
@Farjaad Farjaad force-pushed the advisory-lock-timeout-seconds branch from 56a2ea7 to 547b422 Compare January 28, 2026 21:32
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.

3 participants