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
Delete cache after one click update to avoid un-updated in-memory classes being used. #14236
Conversation
CC @tsteur |
$view->feedbackMessages = $messages; | ||
$this->addCustomLogoInfo($view); | ||
return $view->render(); | ||
} | ||
|
||
public function oneClickResults() | ||
{ | ||
Filesystem::deleteAllCacheOnUpdate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diosmosis I'm not too much into the code... should we maybe just update on both after one click update and one click results?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't do it in the one click update for the same reason we have this special view: https://github.com/matomo-org/matomo/blob/3.x-dev/core/View/OneClickDone.php#L15-L22
This method triggers a lot of code that could be using some out of date classes (in this case Twig was new, but Plugin\Manager was old).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK just to understand correctly: Was it an opcache that prevents this issue? If not using any PHP cache, this might still happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did for me locally (I have opcache disabled). I believe the issue is as follows:
- request begins, plugin manager loads (old Plugin\Manager class is in memory)
- one click update finishes changes Twig.php file (Twig class is not loaded in memory yet)
- Filesystem::deleteAllCacheOnUpdate() is called, we try to get Twig class (new Twig class is in memory)
- new twig class tries to call new Plugin\Manager method, but old class is in memory so it doesn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diosmosis I'm bit confused now. So does it actually help to not invalidate cache anymore in Filesystem::deleteAllCacheOnUpdate();
as it would still load the outdated Twig when not using opcache?
I'm pretty sure we had such issues a few times before. I wonder if we should clear the cache in oneClickUpdate
, and then redirect to a new page where we render the view with the messages (would need to store these in session or so). This would maybe fix it once and for all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there needs to be an intermediate method that deletes the cache and redirects again. Not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe we can invoke a command? That way everything is done in a new process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean invoke command to clear the cache? I was thinking in general once the files have been updated, it is not really safe to use any other class afterwards that wasn't used before. As there can be always issues. That's why I thought redirecting may help and avoid any future issues. In theory there could be even issues with twig templates somehow not being compatible with controller and so on (probably not best example as likely not an issue).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean invoke command to clear the cache?
Yes, via shell_exec()
.
I was thinking in general once the files have been updated, it is not really safe to use any other class afterwards that wasn't used before. As there can be always issues.
This is why OneClickDone is used instead of View/Twig.
That's why I thought redirecting may help and avoid any future issues.
OneClickDone does a redirect, the problem occurs before this when clearing the cache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... had no idea this existed. should be fine then 👍 Wouldn't need to do a shell_exec as it might not work on all systems.
Fixes #14227