Skip to content

[5.8] Locks acquired with block() are not immediately released if the callback fails#27957

Merged
taylorotwell merged 4 commits into
laravel:5.8from
howey-aus:5.8
Mar 21, 2019
Merged

[5.8] Locks acquired with block() are not immediately released if the callback fails#27957
taylorotwell merged 4 commits into
laravel:5.8from
howey-aus:5.8

Conversation

@howey-aus

Copy link
Copy Markdown
Contributor

Currently, after block() successfully acquires a lock, tap() releases the lock only if $callback() is a success. However this won't happen if $callback fails in some way; the lock will only release when it was set to expire since there is nothing ensuring it on $callback's failure.

Contrast this with the behavior of get() which wraps $callback in a try/finally, so the lock is released immediately regardless of the outcome of the callback. This PR ensures block() exhibits the same behavior after successful lock acquisition.

Added redis integration test for this case.

…y if the callback passed to block() threw an exception, the lock would only be released when it expired.

Add integration test.
Comment thread tests/Integration/Cache/RedisCacheLockTest.php
Comment thread tests/Integration/Cache/RedisCacheLockTest.php
Comment thread tests/Integration/Cache/RedisCacheLockTest.php
Comment thread tests/Integration/Cache/RedisCacheLockTest.php Outdated
@driesvints driesvints dismissed their stale review March 21, 2019 14:40

Changes were made

@taylorotwell taylorotwell merged commit e5164f8 into laravel:5.8 Mar 21, 2019
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