nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.32k stars 4.06k forks source link

[Bug]: When running repair steps for the first time, changed classes get not loaded properly #38158

Open dartcafe opened 1 year ago

dartcafe commented 1 year ago

⚠️ This issue respects the following points: ⚠️

Bug description

When updating an app (here it is Polls) via occ it seems that altered classes, which are used inside a repair step get not updated properly (caching??). A second update run then installs the app with out an exception.

Steps to reproduce

See details here: https://github.com/nextcloud/polls/issues/2900 and https://github.com/nextcloud/polls/issues/2793

Expected behavior

changed classes should be loaded properly while updating an app.

Installation method

Community Web installer on a VPS or web space

Nextcloud Server version

26

Operating system

None

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database engine version

MySQL

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "test.yagst.de"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "tempdirectory": "\/tmp\/nextcloud",
        "dbtype": "mysql",
        "version": "26.0.1.1",
        "overwrite.cli.url": "http:\/\/xxx",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "theme": "",
        "loglevel": 0,
        "maintenance": false,
        "ldapIgnoreNamingRules": false,
        "ldapProviderFactory": "OCA\\User_LDAP\\LDAPProviderFactory",
        "app_install_overwrite": [
            "polls"
        ]
    }
}

List of activated Apps

Enabled:
  - activity: 2.18.0
  - admin_audit: 1.16.0
  - bruteforcesettings: 2.6.0
  - circles: 26.0.0
  - cloud_federation_api: 1.9.0
  - comments: 1.16.0
  - contactsinteraction: 1.7.0
  - dashboard: 7.6.0
  - dav: 1.25.0
  - federatedfilesharing: 1.16.0
  - federation: 1.16.0
  - files: 1.21.1
  - files_external: 1.18.0
  - files_pdfviewer: 2.7.0
  - files_rightclick: 1.5.0
  - files_sharing: 1.18.0
  - files_trashbin: 1.16.0
  - files_versions: 1.19.1
  - firstrunwizard: 2.15.0
  - logreader: 2.11.0
  - lookup_server_connector: 1.14.0
  - nextcloud_announcements: 1.15.0
  - notifications: 2.14.0
  - oauth2: 1.14.0
  - password_policy: 1.16.0
  - photos: 2.2.0
  - polls: 5.0.5
  - privacy: 1.10.0
  - provisioning_api: 1.16.0
  - recommendations: 1.5.0
  - related_resources: 1.1.0-alpha1
  - serverinfo: 1.16.0
  - settings: 1.8.0
  - sharebymail: 1.16.0
  - support: 1.9.0
  - survey_client: 1.14.0
  - systemtags: 1.16.0
  - text: 3.7.2
  - theming: 2.1.1
  - twofactor_backupcodes: 1.15.0
  - updatenotification: 1.16.0
  - user_ldap: 1.16.0
  - user_status: 1.6.0
  - viewer: 1.10.0
  - weather_status: 1.6.0
  - workflowengine: 2.8.0
Disabled:
  - encryption: 2.14.0 (installed 2.8.1)
  - suspicious_login: 4.4.0
  - twofactor_totp: 8.0.0-alpha.0

Nextcloud Signing status

Technical information
=====================
The following list covers which files have failed the integrity check. Please read
the previous linked documentation to learn more about the errors and how to fix
them.

Results
=======
- core
    - INVALID_HASH
        - .user.ini

Raw output
==========
Array
(
    [core] => Array
        (
            [INVALID_HASH] => Array
                (
                    [.user.ini] => Array
                        (
                            [expected] => 4843b3217e91f8536cb9b52700efb20300290292cf6286f92794d4cec99df286afeb7dd6c91b1be20bc55eda541eef230a5c5e7dcd46c189edd0ed1e80c6d3f5
                            [current] => 3fecf59adb63f3529c30449b25264e1fd2a447b855afae05821110b50039a5e51f6c4f3349399512602b5544a65cdf6fa3c50b81f16fcbe2e0be175d9f6c4c82
                        )

                )

        )

)

Nextcloud Logs

sudo -u www-data php8.1 ./occ app:update --all
polls new version available: 5.0.5
An unhandled exception has been thrown:
Error: Call to undefined method OCA\Polls\Db\TableManager::deleteAllDuplicates() in /var/www/nc_01/nextcloud/apps/polls/lib/Migration/RepairSteps/DeleteInvalidRecords.php:70
Stack trace:
#0 /var/www/nc_01/nextcloud/lib/private/Repair.php(127): OCA\Polls\Migration\RepairSteps\DeleteInvalidRecords->run()
#1 /var/www/nc_01/nextcloud/lib/private/legacy/OC_App.php(1068): OC\Repair->run()
#2 /var/www/nc_01/nextcloud/lib/private/legacy/OC_App.php(1005): OC_App::executeRepairSteps()
#3 /var/www/nc_01/nextcloud/lib/private/Installer.php(200): OC_App::updateApp()
#4 /var/www/nc_01/nextcloud/core/Command/App/Update.php(107): OC\Installer->updateAppstoreApp()
#5 /var/www/nc_01/nextcloud/apps/recognize/vendor/symfony/console/Command/Command.php(298): OC\Core\Command\App\Update->execute()
#6 /var/www/nc_01/nextcloud/apps/recognize/vendor/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run()
#7 /var/www/nc_01/nextcloud/apps/recognize/vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#8 /var/www/nc_01/nextcloud/apps/recognize/vendor/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#9 /var/www/nc_01/nextcloud/lib/private/Console/Application.php(214): Symfony\Component\Console\Application->run()
#10 /var/www/nc_01/nextcloud/console.php(100): OC\Console\Application->run()
#11 /var/www/nc_01/nextcloud/occ(11): require_once('...')
#12 {main}

Additional info

The method OCA\Polls\Db\TableManager::deleteAllDuplicates() was added in the last Polls version (5.0.5).

The error trace is taken from https://github.com/nextcloud/polls/issues/2900 The system configuration is taken from my test instance, where I could observe this problem too.

szaimen commented 1 year ago

cc @nextcloud/server-backend

ChristophWurst commented 1 year ago

Same with https://github.com/nextcloud/mail/issues/8146 and https://github.com/nextcloud/calendar/issues/5191

Summary: the app migration/repair step are run with a mix of old app code and new app code.

I think the only possible fix is to run migrations and repair steps in a new process

ChristophWurst commented 1 year ago

https://github.com/search?q=repo%3Anextcloud%2Fmail+method_exists+path%3A%2F%5Elib%5C%2FMigration%5C%2F%2F&type=code for all the previous monkey patches

szaimen commented 1 year ago

https://github.com/nextcloud/documentation/pull/10578

dartcafe commented 1 year ago

Obviously there are other problems with apps after an update and a not refreshed cache. I would say there should be a straight solution, since it seems there are a lot of people running into this trap, especially users of hosted Nextcloud solutions, who do not have the necessary admin experience to solve that on their own.

Recently problems after (not durien) an app update:

ChristophWurst commented 1 year ago

Let's keep separate issues separate

1) In-process replacement of code during an app update (this ticket) 2) Lack of opcache refresh after changed code: https://github.com/nextcloud/server/issues/39079

These require two distinct fixes.

dartcafe commented 1 year ago

I assumed, this could be the same fix. Nevermind, I'll hide my comment to avoid useless discussions.

szaimen commented 1 year ago

Possibky this was fixed with https://github.com/nextcloud/server/pull/40349

dartcafe commented 1 year ago

Will check it with 28 beta

ChristophWurst commented 1 year ago

https://github.com/nextcloud/server/issues/38158#issuecomment-1613535701

dartcafe commented 1 year ago

I tried to reproduce this error in 27.1.3 before updating to 28-beta1, but the migration runs thru with new methods. So it seems it is already fixed in 27.

In 28-beta1 the problem does not occur as well.

ChristophWurst commented 1 year ago

I do not think this is fixed. See https://github.com/nextcloud/server/issues/38158#issuecomment-1613535701 for the distinction of the two problems with caching code. One was fixed, the other wasn't.

dartcafe commented 1 year ago

Funny thing. If it is still present, then I did something weird while trying to reproduce it. I was sure, I provocated the issue by adding and calling new methods to the repais steps. I will try my luck again.

Reopen?

ChristophWurst commented 12 months ago

calling new methods to the repais steps

It works if the class hasn't been loaded prior to code replacement.

Works: 1) Nextcloud boots 2) Nextcloud replaces app code 3) Nextcloud runs upgrade routine 4) Upgrade routine loads app class

Doesn't work 1) Nextcloud boots and loads an app class 2) Nextcloud replaces app code 3) Nextcloud runs upgrade routine 4) Upgrade routine calls new method on the old version of the class

joshtrichards commented 1 week ago

Related: #9781