feat: make preventOverlapping lock TTL configurable#121
Open
lunetics wants to merge 1 commit intocrunzphp:3.10from
Open
feat: make preventOverlapping lock TTL configurable#121lunetics wants to merge 1 commit intocrunzphp:3.10from
lunetics wants to merge 1 commit intocrunzphp:3.10from
Conversation
Add optional `int $lockTtl` parameter to `preventOverlapping()` with a default of 30 seconds (preserving backward compatibility). The value is stored in a new `$lockTtl` property and used in `createLockObject()` instead of the previously hardcoded `$ttl = 30`. This allows users of TTL-based lock stores (e.g. RedisStore) to set a longer TTL, avoiding sporadic `LockConflictedException` caused by the probabilistic refresh mechanism not being able to reliably refresh a 30-second lock in time.
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
int $lockTtl = 30parameter topreventOverlapping()(backward compatible)$lockTtlproperty, use it increateLockObject()instead of hardcoded$ttl = 30Fixes #120
Motivation
The hardcoded 30-second lock TTL combined with the probabilistic refresh mechanism (10% chance per 250ms iteration) creates a ~0.18% failure rate per lock operation when using TTL-based stores like
RedisStore. This causes sporadicLockConflictedException— the lock expires before being refreshed.Increasing the TTL (e.g. to 300s) makes the failure probability effectively zero while keeping the same refresh semantics. File-based stores (
FlockStore) are unaffected since their locks don't expire.Changes
src/Event.php:private int $lockTtl = 30;preventOverlapping(?object $store = null, int $lockTtl = 30)createLockObject()uses$this->lockTtlinstead of hardcoded30tests/Unit/EventTest.php:prevent_overlapping_default_lock_ttl_is_30()— verifies backward compatibilityprevent_overlapping_accepts_custom_lock_ttl()— verifies custom TTL (300s)Test plan
phpunit --filter EventTest→ 50 tests, 0 failures)