-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Add lock support for file and null cache drivers #35139
Conversation
Also, added a The tests seem to be failing unrelated to this PR (in the install dependencies step). Perhaps a simple close/re-open bump might be needed. |
@paras-malhotra you can always re-run builds in the actions tab. I've re-triggered them for you. |
Thanks @driesvints, didnt know we could do that. 👍 Tests are still failing for Windows, seems to be some issue with composer installing phpunit. |
Which drivers would have race conditions? |
@taylorotwell, this PR makes the lock dependent on the cache store. A lock acquisition is simply a cache store To be doubly sure, I examined the cache stores themselves. The file cache store uses shared locks for get and exclusive locks for put, so race conditions are taken care of. So, if any data changes between the get and put operations, the For the A case in point would be that the console scheduling cache event mutex operates in the same manner - skips if exists (get operation), creates on run (put operation) and forgets after run (delete operation). Similar to how a lock would work - attempt to acquire (get operation followed by put operation) and release after run (delete operation). |
I'm confused how there would not be a race condition in the file lock. Two processes are attempting to get the lock at about the same time. When both of them call |
@taylorotwell, on a closer review, there is a chance of race conditions in the
Symfony uses |
You could potentially look at adding an Regarding APC, it is probably the least used cache driver of all so I'm not particularly concerned about if we can't support locks on that driver. |
@taylorotwell, I've added the I think we are ready to merge this in. Let me know if you'd like me to make any additional changes. |
Is it possible the file driver fails to lock or something like that? For example, I have the following:
and However, sometimes it isn't unique. This doesn't happen often, but sometimes it happens. I switched to Redis so we'll see if that will happen with Redis too. Thanks! |
This PR adds a generic cache lock class that can implement a lock with any cache store implementation (kind of a bridge that takes a cache store and returns a cache lock). With this PR, we can now support locks for all cache drivers (including file, apc and null).
Laravel uses locks for several things including session blocking,
WithoutOverlapping
job middleware and unique jobs. This PR allows users to use these features for all cache drivers.