Skip to content
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

[Bug]: Autoloading issue for navigation container in conjunction with OPCache #15970

Open
GALPR opened this issue Sep 19, 2023 · 12 comments
Open

Comments

@GALPR
Copy link
Contributor

GALPR commented Sep 19, 2023

Pimcore version

11.0.8

Steps to reproduce

  • Activate PHP OPCache extension
  • Add a call to new \Pimcore\Navigation\Container() anywhere
  • Reload the page where this call is executed multiple times (so that it is definitely cached by OPCache)
  • This issue seems to occur since the following type-hint change: 83142b5#diff-6d072dd8e428eeff1dff129ad1056e39b8a7fdbf8273fa3aee2436a34d482ad4
  • Removing the type-hints for the Page class again resolves this issue

Actual Behavior

The page does not load anymore. I get the following exception logged in the php.log (formatted for readability):

Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: 
"Error: During inheritance of Pimcore\Navigation\Container, while autoloading Pimcore\Navigation\Page: Uncaught Error: Class "Pimcore\Navigation\Container" not found in /var/www/html/vendor/pimcore/pimcore/lib/Navigation/Page.php:44 
Stack trace: 
#0 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(293): include() 
#1 /var/www/html/vendor/pimcore/pimcore/lib/Navigation/Container.php(42): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Pimcore\\Navigat...') 
#2 /var/www/html/vendor/symfony/error-handler/DebugClassLoader.php(293): include('/var/www/html/v...') 
#3 /var/www/html/src/Controller/DefaultController.php(19): Symfony\Component\ErrorHandler\DebugClassLoader->loadClass('Pimcore\\Navigat...') 
#4 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(166): App\Controller\DefaultController->defaultAction(Object(Symfony\Component\HttpFoundation\Request)) 
#5 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) 
#6 /var/www/html/vendor/symfony/http-kernel/Kernel.php(197): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
#7 /var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(35): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
#8 /var/www/html/vendor/autoload_runtime.php(29): Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() 
#9 /var/www/html/public/index.php(22): require_once('/var/www/html/v...') 
#10 {main}" at /var/www/html/vendor/pimcore/pimcore/lib/Navigation/Container.php line 42 {"exception":"..."} []

Expected Behavior

The page should load as normal

@GALPR GALPR added the Bug label Sep 19, 2023
@github-actions
Copy link

Thanks a lot for reporting the issue. We did not consider the issue as "Priority" or "Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.

@GALPR
Copy link
Contributor Author

GALPR commented Jan 10, 2024

Any update / info on this?

@brusch
Copy link
Member

brusch commented Jan 11, 2024

@GALPR As you're experiencing the issue, could you please debug it and provide a PR with the fix?
Thanks a lot in advance!

@GALPR
Copy link
Contributor Author

GALPR commented Jan 11, 2024

The only fix I found that worked was to basically revert the linked change. Let me know if this is a viable solution and I will happily provide a PR. Here is the composer patch I am currently using:

diff --git a/lib/Navigation/Container.php b/lib/Navigation/Container.php
index 5a57e8b..250ce89 100644
--- a/lib/Navigation/Container.php
+++ b/lib/Navigation/Container.php
@@ -39,6 +39,9 @@ declare(strict_types=1);
 
 namespace Pimcore\Navigation;
 
+use RecursiveIterator;
+
 class Container implements \RecursiveIterator, \Countable
 {
     /**
@@ -109,7 +112,7 @@ class Container implements \RecursiveIterator, \Countable
      *
      * @throws \Exception if page is invalid
      */
-    public function addPage(Page|array $page): static
+    public function addPage($page): static
     {
         if ($page === $this) {
             throw new \Exception('A page cannot have itself as a parent');
@@ -189,7 +192,7 @@ class Container implements \RecursiveIterator, \Countable
      *
      * @return bool whether the removal was successful
      */
-    public function removePage(Page|int $page, bool $recursive = false): bool
+    public function removePage($page, bool $recursive = false): bool
     {
         if ($page instanceof Page) {
             $hash = $page->hashCode();
@@ -244,7 +247,7 @@ class Container implements \RecursiveIterator, \Countable
      *
      * @return bool whether page is in container
      */
-    public function hasPage(Page $page, bool $recursive = false): bool
+    public function hasPage($page, bool $recursive = false): bool
     {
         if (array_key_exists($page->hashCode(), $this->_index)) {
             return true;
@@ -508,7 +511,7 @@ class Container implements \RecursiveIterator, \Countable
      *
      * @throws \Exception
      */
-    public function current(): Page
+    public function current()
     {
         $this->_sort();
         $hash = key($this->_index);
@@ -551,7 +554,10 @@ class Container implements \RecursiveIterator, \Countable
         return $this->hasPages();
     }
 
-    public function getChildren(): ?Page
+    /**
+     * @return ?Page
+     */
+    public function getChildren(): ?RecursiveIterator
     {
         $hash = key($this->_index);

@LosHawlos
Copy link
Contributor

I have seen this exact error message in Pimcore version 11.2.2 but I can not reliably reproduce the error.

@GALPR
Copy link
Contributor Author

GALPR commented Apr 16, 2024

@LosHawlos Have you tried if my reproduction consistently leads to this issue for you?

@LosHawlos
Copy link
Contributor

@GALPR I can reproduce it, but not reliably in a reduced test case.

Simply putting
new \Pimcore\Navigation\Container()
into a Controller does not always trigger the error, sometimes it simply works as expected.

It will be triggered when I load a page in Pimcore that does show a navigation using the Navigation Extension. But in the Pimcore Admin I see the strange effect that some pages show the navigation in editmode but fail in preview or frontend mode.

So there seems to be an outside factor related to triggering the error.

But: It seems to be related to the OPCache, because putting
opcache_reset()
into the Controller seems to fix it, but not on every page load.

BTW. I'm running Pimcore in Docker using the image "pimcore/pimcore:php8.2-max-v3".

@GALPR
Copy link
Contributor Author

GALPR commented Apr 17, 2024

@LosHawlos Thanks for the info, definitely seems related. Do you also get the same fatal error in the php.log?

@brusch Any suggestions what an adequate fix could look like?

@brusch
Copy link
Member

brusch commented May 2, 2024

@GALPR for me it would be fine to revert the type-hints here, but we should then add the PhpDoc again as well and leave a comment why we're not using proper type-hints.
Thanks!

@brusch
Copy link
Member

brusch commented May 2, 2024

This should be of course just a quick-fix we need further investigate what's the root-cause of this issue.

@GALPR
Copy link
Contributor Author

GALPR commented May 13, 2024

@brusch Should I branch this off 11.x or 11.2?

@brusch
Copy link
Member

brusch commented May 14, 2024

@GALPR as others seem to be affected by this issue as well, I'd consider it as a bug fix and therefore it should go to 11.2 - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants