Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:6.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
try { | ||
$response = $this->lookup($request, $catch); | ||
} catch (CacheWasLockedException) { | ||
$response = $this->lookup($request, $catch); | ||
} |
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.
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 inlock()
.
Maybe it is even better this way to fail with the exception instead of silenty retrying over and over again?
110274d
toebe451c
CompareThere 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.
what about using a dedicated request attribute instead ?
You mean, proceed with the re-entrant |
I means something like this: $response =$this->lookup($request,$catch);if ($request->attribute->has('foo')) {// lookup again after removing the attribute With an early return in the lock method indeed. |
The return has to be through several methods up the call stack. That would need some kind of check at every level with early returns in each case. |
Hum indeed. |
I am fine with both. Should we be afraid of infinite retries? We could also limit to a certain number of iterations. |
Exception is now |
Uh oh!
There was an error while loading.Please reload this page.
When the
HttpCache
has to wait for a lock held by another, concurrent process, thelock()
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 theno-cache
cache-control header, causing surprising side effects™️ ✨.Also without
no-cache
you can get strange-looking cache traces likestale, 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.