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

Delete cache after one click update to avoid un-updated in-memory classes being used. #14236

Merged
merged 1 commit into from Mar 20, 2019

Conversation

diosmosis
Copy link
Member

Fixes #14227

@diosmosis diosmosis added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Mar 19, 2019
@diosmosis
Copy link
Member Author

CC @tsteur

$view->feedbackMessages = $messages;
$this->addCustomLogoInfo($view);
return $view->render();
}

public function oneClickResults()
{
Filesystem::deleteAllCacheOnUpdate();
Copy link
Member

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?

Copy link
Member Author

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).

Copy link
Member

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?

Copy link
Member Author

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:

  1. request begins, plugin manager loads (old Plugin\Manager class is in memory)
  2. one click update finishes changes Twig.php file (Twig class is not loaded in memory yet)
  3. Filesystem::deleteAllCacheOnUpdate() is called, we try to get Twig class (new Twig class is in memory)
  4. new twig class tries to call new Plugin\Manager method, but old class is in memory so it doesn't work

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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).

Copy link
Member Author

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.

Copy link
Member

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.

@sgiehl sgiehl added this to the 3.9.1 milestone Mar 20, 2019
@diosmosis diosmosis merged commit 274f1be into 3.x-dev Mar 20, 2019
@diosmosis diosmosis deleted the one-click-update-cache branch March 20, 2019 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants