Skip to content

[HttpCache] Hit the backend only once after waiting for the cache lock #60502

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

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
from

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented May 21, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues
License MIT

When the HttpCache has to wait for a lock held by another, concurrent process, the lock() method wants to make sure we continue operation based on the most recent cache entry, possibly updated by the concurrent process.

So, after waiting for lock release, it calls lookup() to obtain this cache entry. This is, in fact, a reentrant call up into the current call stack.

Having lookup() multiple times on the call stack opens up a way to call the backend for validation multiple times. I have observed this in practice at least in combination with the no-cache cache-control header, causing surprising side effects™️ ✨.

Also without no-cache you can get strange-looking cache traces like stale, valid, store, fresh. Those occur only when concurrent locking is a issue.

I am not super happy with using an exception for a control flow issue like this. But, rolling back to lookup seems to be the most sensible decision for me, and using special return values to indicate this condition isn't really pretty either.

@mpdude
Copy link
Contributor Author

mpdude commented May 21, 2025

Test failures seem unrelated

Comment on lines +222 to +226
try {
$response = $this->lookup($request, $catch);
} catch (CacheWasLockedException) {
$response = $this->lookup($request, $catch);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to restart the process only once.

In fact, the old code would wait for the lock to be released, but only try to acquire it later on. That could, in theory, allow for repeated cycles without actually reaching the 503 condition in lock().

Maybe it is even better this way to fail with the exception instead of silenty retrying over and over again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants