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

Error in command line with PageUrlRule component #281

Open
marc-farre opened this issue May 24, 2023 · 10 comments
Open

Error in command line with PageUrlRule component #281

marc-farre opened this issue May 24, 2023 · 10 comments

Comments

@marc-farre
Copy link
Contributor

marc-farre commented May 24, 2023

Related to #86 and #74

On some Humbub instance, I don't know why and cannot reproduce on my local dev instance, each time I execute a command line (e.g. php yii queue/run -v), the command executes correctly up to the end, and just after, Humhub is not working anymore with on the browser: each time a user loads a page, and error is thrown.

php yii cache/flush-all fixes the problem.

Error log:

yii\base\ErrorException: yii\web\UrlManager::parseRequest(): The
script tried to execute a method or access a property of an incomplete
object. Please ensure that the class definition
"humhub\modules\custom_pages\components\PageUrlRule" of the
object you are trying to operate on was loaded _before_ unserialize()
gets called or provide an autoloader to load the class definition in
/var/www/humhub/protected/vendor/yiisoft/yii2/web/UrlManager.php:325
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
@luke-
Copy link
Contributor

luke- commented May 24, 2023

@gevorgmansuryan Any idea?

@gevorgmansuryan
Copy link
Contributor

gevorgmansuryan commented May 26, 2023

@luke- will try to reproduce/understand

@marc-farre
Copy link
Contributor Author

@luke- will try to reproduce/understand

Thanks @gevorgmansuryan ! Don't hesitate if I can help.

@gevorgmansuryan
Copy link
Contributor

@funkycram thank you. Can you please try to reproduce, and see what jobs are executing. It will help me to find job that using cache incorrectly (uses yii\WEB\UrlRule from cli). 99% it is related to UrlRules caching.

@marc-farre
Copy link
Contributor Author

@gevorgmansuryan the bug doesn't occurs with jobs, but when executing a command line with SSH, e.g. php yii queue/run -v, but it occurs with any command, except php yii cache/flush-all

I can reproduce only on Humhub instances on production (where many people are using the platform during my tests). If I clone the humhub to have a dev instance, I cannot reproduce the bug, and the only difference I can see is that nobody is using the dev instance.

I have 2 ways to solve the bug:

  • waiting for the next cron job (the queue/run every minute)
  • flushing the cache by executing the php yii cache/flush-all command

In the settings, "Cache Backend" is set to "File".

@gevorgmansuryan
Copy link
Contributor

@funkycram yeah, i know that it's doesn't occurs with jobs. There is some job or command that calls/uses Web/UrlManager and stores incorrect cache of Rules. Since i can not reproduce it anyway, there is no other chance to reproduce it and find the problem.
We can try to:

  • move urlManager config keys from common.php to web.php and try to run commands/queue and see what will happen. Most probably we'll see the error in file which uses UrlManager
  • try the same with enabled debug mode

@marc-farre
Copy link
Contributor Author

@gevorgmansuryan thanks for you suggestions.
In the 'components` section, I moved

        'urlManager' => [
            'showScriptName' => false,
            'enablePrettyUrl' => true,
        ],

from common.php to web.php.

The problem is still there.

Then, in /index.php, I uncommented defined('YII_DEBUG') or define('YII_DEBUG', true); (only this line, not the YII_ENV one).
This solves the problem.

I tried commenting it and uncommenting it again, and this is really what makes the difference systematically.

@gevorgmansuryan
Copy link
Contributor

gevorgmansuryan commented May 31, 2023

@funkycram interesting :) Can you please comment back YII_DEBUG line, change line 47 from protected/humhub/components/bootstrap/ModuleAutoLoader.php to if (true || $modules === false || YII_DEBUG) { and try again?

@marc-farre
Copy link
Contributor Author

@gevorgmansuryan It works with these changes (the bug is gone)!

I tested 3 cache types:

  • No caching: no bug
  • File: the bug occurs
  • APCu: no bug (but cannot be used when more than 1 Humhub instance is installed on the same server)

The bug occurs only on this server, for all Humhub instances installed on it.
So it's a problem of cache with this server (but that occurs on other servers too as we have this bug mentionned on #86 and #74).

I've checked all server settings with the doc, and "Administration" -> "Information" -> "Prerequisites". Everything seems ok.
Config: Ubuntu 20.04 / PHP 7.4 / mod_php

I've done the folowing test in command line (Controller extending yii\console\Controller):

        echo Yii::$app->cache->get('test_key');
        Yii::$app->cache->set('test_key', 'test value');

At the second execution, the "test value" is shown. So caching works.

Thanks for your investigation!

@marc-farre
Copy link
Contributor Author

marc-farre commented Jun 16, 2023

@gevorgmansuryan have you got an idea how to fix this problem without having to add code in the core ModuleAutoLoader class or to enable debug? Thanks!

If it can help, we can have a video call with screen sharing.

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