-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Lock] Scoped Lock #22115
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
[Lock] Scoped Lock #22115
Conversation
ping @jderusse |
Do we include the documentation in the main component PR, or I create a new one based on the first one? |
Tests are failing for php 7.1 with lowest dependencies. It does not looks related to my PR https://travis-ci.org/symfony/symfony/jobs/214019847#L3293-L3323. |
Trying the solve test failure in #22119 |
LGTM. |
While I generally think this is a great feature, there are some caveats to relying on the destructor for releasing locks where the Lock Component's destructor will not be called, causing the lock to persist, specifically:
The lock will persist in all the above, and possibly other, cases. We should be clear about these caveats in the documentation for this PR, IMHO. |
Stores are made to avoid to keep a lock for ever (segfault and brutal interrupt are handled) thank to the TTL mechanism (but it's not perfect) But you're right. We can add to the list:
|
@robfrawley, all cases you listed are not specific to the scoped lock. So like @jderusse said, you can only rely on the lock timeout. What about a warning in the scoped lock dock about the two points @jderusse listed? |
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.
Very nice contribution!
*/ | ||
public function createScopedLock($resource, $ttl = 300.0) | ||
{ | ||
$lock = $this->createLock($resource, $ttl); |
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.
Thoughtless OTV, consider removing it.
* Create a scoped lock for the given resource. | ||
* | ||
* @param string $resource The resource to lock | ||
* @param float $ttl maximum expected lock duration |
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.
In what unit? Please document that.
namespace Symfony\Component\Lock; | ||
|
||
/** | ||
* ScopedLock encapsulate a LockInterface which is automatically released when destructed. |
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.
"encapsulateS"
} | ||
|
||
/** | ||
* Automatically release the underlying lock when object is destructed. |
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.
"when the object"
Broken tests are addressed in #22122 |
@greg0ire I addressed all changes you requested. |
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.
👌
@fbourigault I just think we should mention these caveats in the documentation PR, is all. |
I'm 👎 here. This makes releasing totally implicit. That's a foot gun to me.
Adding a decorator to provide an unreliable behavior looks like... unreliable, thus my stand. |
Closing for the reasons explained by @nicolas-grekas |
…jderusse) This PR was squashed before being merged into the 3.4 branch (closes #22132). Discussion ---------- [Lock] Automaticaly release lock when user forget it | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The objective of this PR is to automatically release the Lock when the user forget to call the `release` method (like the `fclose` function does in, php core). The implementation is comparable to #22115 but the purpose is not the same. I create a new PR to not mix things. Commits ------- 2eedc1f [Lock] Automaticaly release lock when user forget it
This add to the just-born Lock component a scoped lock.
A scoped lock is a lock which will get automatically released when destructed.
Usage