Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Open
mpdude wants to merge2 commits intosymfony:6.4
base:6.4
Choose a base branch
Loading
frommpdude:hit-backend-once-cache-lock

Conversation

mpdude
Copy link
Contributor

@mpdudempdude commentedMay 21, 2025
edited
Loading

QA
Branch?6.4
Bug fix?yes
New feature?no
Deprecations?no
Issues
LicenseMIT

When theHttpCache 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 callslookup() to obtain this cache entry. This is, in fact, a reentrant call up into the current call stack.

Havinglookup() 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 withoutno-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 tolookup seems to be the most sensible decision for me, and using special return values to indicate this condition isn't really pretty either.

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

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?

@mpdudempdudeforce-pushed thehit-backend-once-cache-lock branch from110274d toebe451cCompareMay 30, 2025 13:16
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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 ?

@mpdude
Copy link
ContributorAuthor

You mean, proceed with the re-entrantlookup from inside/after waiting for the lock, but then indicate on the request that it performed validation etc. and so the "outer" method invocations return immediately?

@nicolas-grekas
Copy link
Member

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.
Should this be in a loop BTW?

@mpdude
Copy link
ContributorAuthor

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.

@nicolas-grekas
Copy link
Member

Hum indeed.
Then let's make the added exception internal.
Also : what about a loop instead of just one retry?

@mpdude
Copy link
ContributorAuthor

I am fine with both. Should we be afraid of infinite retries? We could also limit to a certain number of iterations.

@mpdude
Copy link
ContributorAuthor

Exception is now@internal, and also looping until a response can be obtained

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees
No one assigned
Projects
None yet
Milestone
6.4
Development

Successfully merging this pull request may close these issues.

3 participants
@mpdude@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp