fix(httpcache): attempt every purge request and report all failures - #8592
Open
silverbackdan wants to merge 2 commits into
Open
silverbackdan wants to merge 2 commits into
silverbackdan wants to merge 2 commits into
Conversation
Contributor
Author
|
I'll be honest with this and say I'm too tired right now to properly review and am about to go on a holiday. But on a brief look over it all seemed pretty plausible and effective solutions to the issue - I'm not entirely sure or opinionated on the |
SurrogateKeysPurger (and so SouinPurger and VarnishXKeyPurger) and VarnishPurger discarded each purge response, so its destructor waited for it and threw on the first transport error or 3xx+ status. That abandoned every remaining client and chunk, sent requests one at a time, and, for surrogate keys, could purge earlier chunks before rejecting a later one as too long. Chunks are now validated before anything is sent. Every request is sent first, so they run concurrently, and the responses are checked afterwards. If any failed, a PurgeFailedException lists each failure (URL, header, cause) with the first one as previous. It extends ApiPlatform\Metadata\Exception\RuntimeException and implements HttpClient's ExceptionInterface, so existing catch blocks still catch it.
Each response now travels alone in the list, and the header name and value it was sent with are read back from user_data when a request fails, instead of being carried in a tuple beside the response.
silverbackdan
force-pushed
the
fix/purger-attempt-all-requests
branch
from
September 25, 2026 19:53
3cfaf32 to
a473e5e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
SurrogateKeysPurger(the base ofSouinPurgerandVarnishXKeyPurger) andVarnishPurgerused to discard eachrequest()result. Symfony HttpClient's response destructor then ran immediately, waited for the response and threw on any error. As a result, requests were sequential, the first failure abandoned every remaining client and chunk, and the "IRI too long" check could fire after earlier chunks had already been purged.Now:
SurrogateKeysPurgerchecks every chunk's length before sending anything. The "too long"RuntimeExceptionkeeps its type and message, but now nothing has been purged when it's thrown.getHeaders(), which throws on transport errors and on statuses ≥ 300, as the destructor did.ApiPlatform\HttpCache\Exception\PurgeFailedExceptionis thrown after all requests have been attempted.ApiPlatform\Metadata\Exception\RuntimeExceptionand implementsSymfony\Contracts\HttpClient\Exception\ExceptionInterface, so existingcatch (ExceptionInterface …)blocks still catch it.getFailures()returns aPurgeFailurefor each failed request: the URL, the header name and value (the tag chunk or ban regex), and the cause.previous, and the message reads "N of M HTTP cache purge requests failed."user_dataoption, so the response list stays a plain list of responses.Method, headers, chunking,
getResponseHeaders()and constructor signatures are unchanged.Tests
New tests for both purgers use
MockHttpClient, with no Prophecy in new tests per CONTRIBUTING. Each was seen failing on5.0first:previous;ExceptionInterfaceand the API PlatformRuntimeException;A no-failure guard test passes before and after.
cd src/HttpCache && vendor/bin/phpunit: 48 tests pass.Existing tests edited: the Prophecy expectations in
SouinPurgerTest,VarnishPurgerTestandVarnishXKeyPurgerTestnow include theuser_dataoption. Some also gained->willReturn(new MockResponse()), because a null response can no longer be checked. CONTRIBUTING asks for existing tests to be left alone where possible; these are mechanical updates to the exact request options, with no behavioural change.Open questions
4.4as a bug fix, so it reaches5.0andmainthrough the usual up-merge. The code insrc/HttpCacheis identical on4.4and5.0, and the 48 component tests pass on both. If you would rather treat the new exception class as a feature for5.0ormain, the two commits rebase onto either branch without changes.PurgeFailedExceptioneven when exactly one request failed (consistent), or rethrow the original exception in that case (so narrower catches such asServerExceptionInterfacestill match)?ExceptionInterfaceno longer matches. Is that acceptable in a patch release?VarnishXKeyPurgerTestbuilds the purger with Guzzle PSR clients, although the constructor documentsHttpClientInterface[]. The success path still works with them. The failure path relies on HttpClient'sgetInfo(), and Guzzle raises its own errors fromrequest()instead. Is Guzzle still meant to be supported here?api-platform/http-cachedoesn't requiresymfony/http-client-contracts, although the new exception implements one of its interfaces. Should it be declared?🤖 Generated with Claude Code