Repository navigation
fix(symfony): reset the HTTP cache purger between requests - #8857
Open
KevinMartinsDev wants to merge 1 commit into
Open
KevinMartinsDev wants to merge 1 commit into
KevinMartinsDev wants to merge 1 commit into
Conversation
Doctrine does not dispatch postFlush when the commit fails, so the tags PurgeHttpCacheListener collected in onFlush and preUpdate stayed in the shared service and were purged by the next successful flush of the worker, during another request. The listener now implements ResetInterface and is tagged kernel.reset, and postFlush() clears its tags even when the purge throws.
KevinMartinsDev
force-pushed
the
fix/reset-http-cache-purger
branch
from
November 16, 2026 21:32
41ff32c to
65fbc3d
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.
PurgeHttpCacheListenercollects the tags (IRIs) of the changed resources inpreUpdateandonFlush, and purges them inpostFlush, which then clears the list. Same root cause as #8684: Doctrine only dispatchespostFlushwhen the commit succeeds. When it fails (unique or check constraint, deadlock, lost connection…), the collected tags stay in the listener.With a long-running process (FrankenPHP worker mode, RoadRunner, Swoole, a Messenger consumer), the listener is shared, so the next successful flush of the worker purges them together with its own tags, whoever made that request. Reproduced on API Platform 5.0.8 with a FrankenPHP worker (one thread) and
http_cache.invalidationenabled:The impact is low: superfluous purges, no data exposed (the tags are IRIs).
postFlush()also cleared the tags only after the purge, so when the purger throws (cache server down), the list kept growing from one request to the next.This PR, like #8684:
ResetInterface, with areset()method that clears the tags and the scheduled insertions;kernel.reset(on_invalid: ignore), so the services resetter clears it between requests and Messenger messages;finallyafter the purge, so a failing purger does not make it grow.On
main, the ODM service (doctrine_odm_http_cache_purger.php) needs the samekernel.resettag when this is merged up; it does not exist on 4.4.Tests:
ApiPlatformExtensionTest::testHttpCachePurgerIsReset, and two listener tests: the tags of a flush whose commit failed are not purged afterreset(), and a purge that throws does not leave its tags for the next flush. They fail without the fix.