-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[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
[HttpCache] Hit the backend only once after waiting for the cache lock #60502
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 in lock().
Maybe it is even better this way to fail with the exception instead of silenty retrying over and over again?
110274d to
ebe451c
Compare
nicolas-grekas
left a comment
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.
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 attributeWith 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 |
0b6199e to
df064b0
Compare
|
Thank you @mpdude. |
|
Merging minutes before being a conference host in a live video stream 🤓 |
When the
HttpCachehas 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-cachecache-control header, causing surprising side effects™️ ✨.Also without
no-cacheyou 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
lookupseems to be the most sensible decision for me, and using special return values to indicate this condition isn't really pretty either.