Skip to content

[Cache] Fix possible infinite loop in CachePoolPass #53593

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

Merged

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented Jan 20, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

Introduced in #41353.

I'm not sure what the purpose of this code is exactly, since I haven't actually run into a problem, but it's definitely wrong this way.

@xabbuh
Copy link
Member

xabbuh commented Jan 20, 2024

The change itself looks good. But can you please add a test case to prevent future regressions?

@HypeMC HypeMC force-pushed the fix-infinite-loop-in-cachepoolpass branch from 49c2536 to 58212ad Compare January 20, 2024 22:31
@HypeMC
Copy link
Contributor Author

HypeMC commented Jan 20, 2024

The change itself looks good. But can you please add a test case to prevent future regressions?

@xabbuh Done, but I had to make additional changes to the code. Either I misunderstood the intention, or this code is also broken on v5.4. If that's the case, please let me know, and I'll open a separate PR for v5.4, which should then be merged first.

$aliasedCacheClearerId = (string) $container->getAlias('cache.global_clearer');
$notAliasedCacheClearerId = 'cache.global_clearer';
while ($container->hasAlias($notAliasedCacheClearerId)) {
$notAliasedCacheClearerId = (string) $container->getAlias($notAliasedCacheClearerId);
Copy link
Contributor Author

@HypeMC HypeMC Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $clearers array should only use non-alias names for keys since $container->getDefinition() (on line 193) doesn't work with aliases.

@nicolas-grekas
Copy link
Member

Can you please send the PR you have in mind for 5.4?
Also please target 6.3 for this one as we're going to do one more release of it as patch could be part of it.

@HypeMC HypeMC force-pushed the fix-infinite-loop-in-cachepoolpass branch from 58212ad to 9aa89aa Compare January 22, 2024 23:30
@HypeMC HypeMC changed the base branch from 6.4 to 5.4 January 22, 2024 23:31
@HypeMC HypeMC force-pushed the fix-infinite-loop-in-cachepoolpass branch from 9aa89aa to f971882 Compare January 22, 2024 23:31
@HypeMC
Copy link
Contributor Author

HypeMC commented Jan 22, 2024

@nicolas-grekas I've retargeted this PR to 5.4. A conflict is inevitable when merging with the upstream, so IMO, it would be easiest to resolve it then. Here's the resolved code:

diff --git a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
index 5055ba9918..ab212e8ee2 100644
--- a/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
+++ b/src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php
@@ -181,11 +181,11 @@ class CachePoolPass implements CompilerPassInterface
             $container->removeDefinition('cache.early_expiration_handler');
         }
 
-        $notAliasedCacheClearerId = $aliasedCacheClearerId = 'cache.global_clearer';
-        while ($container->hasAlias('cache.global_clearer')) {
-            $aliasedCacheClearerId = (string) $container->getAlias('cache.global_clearer');
+        $notAliasedCacheClearerId = 'cache.global_clearer';
+        while ($container->hasAlias($notAliasedCacheClearerId)) {
+            $notAliasedCacheClearerId = (string) $container->getAlias($notAliasedCacheClearerId);
         }
-        if ($container->hasDefinition($aliasedCacheClearerId)) {
+        if ($container->hasDefinition($notAliasedCacheClearerId)) {
             $clearers[$notAliasedCacheClearerId] = $allPools;
         }

If needed, I'll create a new PR for 6.3.

@HypeMC HypeMC force-pushed the fix-infinite-loop-in-cachepoolpass branch from f971882 to 7cd9f93 Compare January 23, 2024 08:26
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 5.4 Jan 23, 2024
@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit 1b62f3c into symfony:5.4 Jan 23, 2024
@HypeMC HypeMC deleted the fix-infinite-loop-in-cachepoolpass branch January 23, 2024 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants