Skip to content

Use flock() based locking in HttpCache instead of lock files #16777

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

Closed
mpdude opened this issue Dec 1, 2015 · 0 comments
Closed

Use flock() based locking in HttpCache instead of lock files #16777

mpdude opened this issue Dec 1, 2015 · 0 comments

Comments

@mpdude
Copy link
Contributor

mpdude commented Dec 1, 2015

This is a follow-up for #15813 (comment).

When a PHP process crashes or terminates (maybe the OOM killer kicks in or other bad things ™️ happen) while the HttpCache holds a .lck file, that lock file may not get unlink()ed.

The result is that other requests trying to access this cache entry will see a few seconds delay while waiting for the lock; they will eventually continue but send 503 status codes along with the response. The sudden buildup of PHP processes caused by the additional delay may cause further problems (sudden load increase).

One solution might be to use the LockHandler from the Filesystem component. It applies flock()-based locking, so the lock will automatically be released when the process holding it terminates.

As the LockHandler was added in 2.6, this is not a bugfix we could provide for 2.3.

(Yes, I've seen this happen quite a few time in practice.)

nicolas-grekas added a commit that referenced this issue Jul 28, 2016
This PR was merged into the 2.7 branch.

Discussion
----------

[HttpKernel] Use flock() for HttpCache's lock files

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | #16777, #15813 and #16312 are also related
| License       | MIT
| Doc PR        |

When a PHP process crashes or terminates (maybe the OOM killer kicks in or other bad things ™️ happen) while the `HttpCache` holds a `.lck` file, that lock file may not get `unlink()`ed.

The result is that other requests trying to access this cache entry will see a few seconds delay while waiting for the lock; they will eventually continue but send 503 status codes along with the response. The sudden buildup of PHP processes caused by the additional delay may cause further problems (sudden load increase).

As `LockHandler` is using `flock()`-based locking, locks should be released by the OS when the PHP process terminates.

I wrote this as bugfix against 2.7 because every once in a while I encounter situations (not always reproducible) where `.lock` files are left over and keep the cache locked.

Commits
-------

2668edd [HttpKernel] Use flock() for HttpCache's lock files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants