server icon indicating copy to clipboard operation
server copied to clipboard

[Bug]: QueryNotFoundException in app after changing file structure for Nextcloud 27

Open pbek opened this issue 2 years ago • 22 comments

⚠️ This issue respects the following points: ⚠️

Bug description

For https://github.com/pbek/qownnotesapi/issues/43#issuecomment-1589086217 (OCP\AutoloadNotAllowedException: Autoload path not allowed: /var/www/html/custom_apps/qownnotesapi/appinfo/application.php and follow-up errors) I had to get the file structure of the app "qownnotesapi" up to date for it to work in Nextcloud 27.

e.g. move controller/noteapicontroller.php to lib/Controller/NoteApiController.php, see https://github.com/pbek/qownnotesapi/commit/64652537d8bc6e918ccc8ff13730702f0d07d9b4.

I tested with a fresh installation of Nextcloud 26 and 27 (docker) and had no issues using the app with QOwnNotes.

I put the updated app into the store and later updated the app on my existing installation of Nextcloud 26 (docker).

There I got the exception OC\AppFramework\Utility\QueryNotFoundException: Could not resolve OCA\QOwnNotesAPI\Controller\NoteApiController! Class "OCA\QOwnNotesAPI\Controller\NoteApiController" does not exist when using the API of the app (https://github.com/pbek/qownnotesapi/issues/45)!

The file is existing in custom_apps/qownnotesapi/lib/Controller/NoteApiController.php.

  • I tried removing qownnotesapi and installing it again.
  • ./occ integrity:check-app qownnotesapi went through
  • ./occ maintenance:repair didn't help

Why isn't Nextcloud finding the Controller? Is there an autoloader that needs refreshing? I couldn't find any...

Steps to reproduce

  1. Take an existing installation of Nextcloud 26 with QOwnNotesAPI < 23.6.0 already installed (I can't reproduce it in a fresh installation where QOwnNotesAPI is installed for the first time)
  2. Update QOwnNotesAPI to 23.6.0
  3. Try to access the note versions or trashed notes in QOwnNotes
  4. Get exception OC\AppFramework\Utility\QueryNotFoundException: Could not resolve OCA\QOwnNotesAPI\Controller\NoteApiController! Class "OCA\QOwnNotesAPI\Controller\NoteApiController" does not exist in Nextcloud logs.

Expected behavior

QOwnNotesAPI behaves after an update the same in existing installations and fresh installations.

Installation method

Community Docker image

Nextcloud Server version

26

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.2

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?

Encryption is Disabled

What user-backends are you using?

  • [X] Default user-backend (database)
  • [ ] LDAP/ Active Directory
  • [ ] SSO - SAML
  • [ ] Other

Configuration report

{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "default_language": "en",
        "dbtype": "mysql",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "mysql.utf8mb4": true,
        "version": "26.0.2.1",
        "trusted_domains": [
            "my.domain.com"
        ],
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "password": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "forcessl": true,
        "maintenance": false,
        "secret": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "https:\/\/my.domain.com",
        "overwriteprotocol": "https",
        "twofactor_enforced": "true",
        "twofactor_enforced_groups": [],
        "twofactor_enforced_excluded_groups": [],
        "theme": "",
        "loglevel": 2,
        "mail_smtpmode": "smtp",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_sendmailmode": "smtp",
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
            "keeweb",
            "bruteforcesettings",
            "qownnotesapi",
            "apporder",
            "drawio",
            "news",
            "files_markdown",
            "onlyoffice",
            "integration_whiteboard",
            "impersonate",
            "gpoddersync"
        ],
        "default_phone_region": "AT",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauthtype": "PLAIN",
        "mail_smtpauth": 1,
        "mail_smtpport": "587",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpsecure": "tls"
    }
}

List of activated Apps

Enabled:
  - activity: 2.18.0
  - bruteforcesettings: 2.6.0
  - calendar: 4.4.2
  - circles: 26.0.0
  - cloud_federation_api: 1.9.0
  - comments: 1.16.0
  - contacts: 5.3.0
  - contactsinteraction: 1.7.0
  - dashboard: 7.6.0
  - dav: 1.25.0
  - deck: 1.9.2
  - drawio: 2.1.1
  - 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
  - gpoddersync: 3.7.1
  - keeweb: 0.6.12
  - logreader: 2.11.0
  - lookup_server_connector: 1.14.0
  - mail: 3.2.0
  - news: 21.2.0
  - nextcloud_announcements: 1.15.0
  - nextpod: 0.7.1
  - notes: 4.8.0
  - notifications: 2.14.0
  - oauth2: 1.14.0
  - onlyoffice: 7.8.0
  - password_policy: 1.16.0
  - photos: 2.2.0
  - polls: 5.0.5
  - privacy: 1.10.0
  - provisioning_api: 1.16.0
  - qownnotesapi: 23.6.0
  - recommendations: 1.5.0
  - related_resources: 1.1.0-alpha1
  - serverinfo: 1.16.0
  - settings: 1.8.0
  - sharebymail: 1.16.0
  - side_menu: 3.8.0
  - survey_client: 1.14.0
  - suspicious_login: 4.4.0
  - systemtags: 1.16.0
  - tasks: 0.15.0
  - text: 3.7.2
  - text_templates: 1.0.1
  - theming: 2.1.1
  - twofactor_backupcodes: 1.15.0
  - twofactor_totp: 8.0.0
  - updatenotification: 1.16.0
  - user_status: 1.6.0
  - viewer: 1.10.0
  - weather_status: 1.6.0
  - workflowengine: 2.8.0
Disabled:
  - admin_audit: 1.16.0
  - bookmarks: 13.0.1 (installed 13.0.1)
  - encryption: 2.14.0
  - impersonate: 1.13.1 (installed 1.13.1)
  - integration_whiteboard: 0.0.14 (installed 0.0.14)
  - maps: 1.0.2 (installed 1.0.2)
  - spreed: 16.0.4 (installed 16.0.4)
  - support: 1.9.0 (installed 1.1.0)
  - user_ldap: 1.16.0

Nextcloud Signing status

No response

Nextcloud Logs

Error	index	OC\AppFramework\Utility\QueryNotFoundException: Could not resolve OCA\QOwnNotesAPI\Controller\NoteApiController! Class "OCA\QOwnNotesAPI\Controller\NoteApiController" does not exist

    /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php - line 142:

    OC\AppFramework\Utility\SimpleContainer->resolve("OCA\\QOwnNo ... r")

    /var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php - line 493:

    OC\AppFramework\Utility\SimpleContainer->query("OCA\\QOwnNo ... r")

    /var/www/html/lib/private/AppFramework/DependencyInjection/DIContainer.php - line 465:

    OC\AppFramework\DependencyInjection\DIContainer->queryNoFallback("OCA\\QOwnNo ... r")

    /var/www/html/lib/private/AppFramework/App.php - line 162:

    OC\AppFramework\DependencyInjection\DIContainer->query("OCA\\QOwnNo ... r")

    /var/www/html/lib/private/Route/Router.php - line 315:

    OC\AppFramework\App::main("OCA\\QOwnNo ... r", "getAllVersions", [ "OC\\AppFr ... "], [ "qownnotes ... "])

    /var/www/html/lib/base.php - line 1058:

    OC\Route\Router->match("/apps/qownn ... s")

    /var/www/html/index.php - line 36:

    OC::handleRequest()


### Additional info

_No response_

pbek avatar Jun 13 '23 18:06 pbek

cc @ChristophWurst @juliushaertl as you recently worked with autoloaders ;)

kesselb avatar Jun 13 '23 20:06 kesselb

After updating the whole server to nextcloud:27-apache QOwnNotesAPI works again. But I already have a report of another user with Nextcloud 26 who got the same error... I really would need to know how to initialize the autoloader, so that I can tell users of QOwnNotes how to get around this issue.

OCP\AutoloadNotAllowedException: Autoload path not allowed seems to be the new theme in Nextcloud 27, I now get a OCP\AutoloadNotAllowedException: Autoload path not allowed: /var/www/html/custom_apps/onlyoffice/appinfo/application.php in /var/www/html/lib/autoloader.php:141 with the latest OnlyOffice 7.8.0 Nextcloud App... (https://github.com/ONLYOFFICE/onlyoffice-nextcloud/issues/830) 😅

pbek avatar Jun 14 '23 11:06 pbek

https://github.com/nextcloud/previewgenerator/issues/333 sounds similar

ChristophWurst avatar Jun 14 '23 11:06 ChristophWurst

For pbek/qownnotesapi#43 (comment) (OCP\AutoloadNotAllowedException: Autoload path not allowed: /var/www/html/custom_apps/qownnotesapi/appinfo/application.php and follow-up errors) I had to get the file structure of the app "qownnotesapi" up to date for it to work in Nextcloud 27.

e.g. move controller/noteapicontroller.php to lib/Controller/NoteApiController.php, see pbek/qownnotesapi@6465253.

That is expected. See https://docs.nextcloud.com/server/stable/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_26.html#planned-removal-of-psr-0-class-loading and https://docs.nextcloud.com/server/stable/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_27.html#removal-of-psr-0-class-loader.

ChristophWurst avatar Jun 14 '23 11:06 ChristophWurst

For debugging comment out injected services of NoteApiController one-by-one until the class NoteApiController can be resolved again. If you end up with no more injections, it's the controller itself that can't be loaded. Otherwise it is one of the services.

ChristophWurst avatar Jun 14 '23 11:06 ChristophWurst

For pbek/qownnotesapi#43 (comment) (OCP\AutoloadNotAllowedException: Autoload path not allowed: /var/www/html/custom_apps/qownnotesapi/appinfo/application.php and follow-up errors) I had to get the file structure of the app "qownnotesapi" up to date for it to work in Nextcloud 27. e.g. move controller/noteapicontroller.php to lib/Controller/NoteApiController.php, see pbek/qownnotesapi@6465253.

That is expected. See https://docs.nextcloud.com/server/stable/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_26.html#planned-removal-of-psr-0-class-loading and https://docs.nextcloud.com/server/stable/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_27.html#removal-of-psr-0-class-loader.

Ok, thank you, I was looking for that information! So my changes to QOwnNotesAPI were necessary! The question remains why Nextcloud doesn't seem to detect the new file structure (that all "newer" apps already use).

pbek avatar Jun 14 '23 11:06 pbek

opcache? check if restarting the web server helps

ChristophWurst avatar Jun 14 '23 11:06 ChristophWurst

opcache? check if restarting the web server helps

I had that in mind too (or maybe Redis?) Dunno, it runs in a docker container. Does the opcache leak out of the container? I need a system with the issue again. I need to get the other user with the issue on GitHub...

@fyrfli, are you @fyrfli:matrix.org? (sorry if not)

pbek avatar Jun 14 '23 11:06 pbek

opcache should only be available in that one instance. if you replace the container the cached data should be gone.

could there be two versions of the app? I've seen that with some docker setups. e.g. apps-extra vs apps-writeable.

ChristophWurst avatar Jun 14 '23 11:06 ChristophWurst

For debugging comment out injected services of NoteApiController one-by-one until the class NoteApiController can be resolved again. If you end up with no more injections, it's the controller itself that can't be loaded. Otherwise it is one of the services.

You mean commenting out the injected services in: https://github.com/pbek/qownnotesapi/blob/a2a5d018559bc5619299938975917134abdc6238/lib/Controller/NoteApiController.php#L32-L34

pbek avatar Jun 14 '23 12:06 pbek

opcache should only be available in that one instance. if you replace the container the cached data should be gone.

Too bad that after updating the container to nextcloud:27-apache the issue was gone, would have been a great test to restart the container.

could there be two versions of the app? I've seen that with some docker setups. e.g. apps-extra vs apps-writeable.

No, only one version

pbek avatar Jun 14 '23 12:06 pbek

https://github.com/ONLYOFFICE/onlyoffice-nextcloud/issues/830#issuecomment-1591092260 seems the same issue. Restarting the webserver and phpfpm did help too.

pbek avatar Jun 14 '23 12:06 pbek

Then it might be the autoload cache in apcu (if this is enabled) where the webserver restart would clear the cache.

Quoting https://github.com/nextcloud/calendar/issues/5191#issuecomment-1567926928:

I've been thinking if this was related to the apcu autoloader cache which is not refreshed during app upgrade:

https://github.com/nextcloud/server/blob/d293293cdaf10745459e98cce70412882241fdec/lib/base.php#L609

Ideally we'd have a prefix including app versions, but might be too early in the request to do that, so maybe we can workaround by adding a apcu_clear_cache during the app upgrade process somewhere around here: https://github.com/nextcloud/server/blob/b1ec7ff51f2ca3278314beffce547b579a050559/lib/private/legacy/OC_App.php#L840

https://github.com/nextcloud/server/issues/38158 seems more generic to already loaded classes, but I think the more recent problem is just there for new classes where the cached authoritative autoloader is reused.

juliusknorr avatar Jun 14 '23 12:06 juliusknorr

After updating to the OnlyOffice App 8.0.0 I also got the error message OC\AppFramework\Utility\QueryNotFoundException: Could not resolve OCA\Onlyoffice\AppInfo\Application! Class "OCA\Onlyoffice\AppInfo\Application" does not exist.

After removing the Nextcloud Docker container and starting it up again, the message was gone and OnlyOffice worked fine! (https://github.com/ONLYOFFICE/onlyoffice-nextcloud/issues/830#issuecomment-1591669728)

There we have our answer about restarting the container (by removing it).

pbek avatar Jun 14 '23 17:06 pbek

Should I close this issue, or should it be addressed more?

pbek avatar Jun 14 '23 17:06 pbek

opcache? check if restarting the web server helps

I had that in mind too (or maybe Redis?) Dunno, it runs in a docker container. Does the opcache leak out of the container? I need a system with the issue again. I need to get the other user with the issue on GitHub...

@fyrfli, are you @fyrfli:matrix.org? (sorry if not)

(yes i am the same @fyrfli)

so i got on my docker container and did the following:

  • php occ app:remove qownnotes
  • php occ maintenance:repair
  • php occ app:install qownnotes
  • php occ maintenance:repair
  • tried to connect from the desktop app again and here is the exact error i get:
  Error    index              OC\AppFramework\Utility\QueryNotFoundException: Could not resolve OCA\QOwnNotesAPI\Controller\NoteApiController! Class 2023-06-14T22:04:33+00:00
                              "OCA\QOwnNotesAPI\Controller\NoteApiController" does not exist at .../private/AppFramework/Utility/SimpleContainer.php
                              line 131

                              0. .../private/AppFramework/Utility/SimpleContainer.php line 142
                                 OC\AppFramework\Utility\SimpleContainer->resolve("OCA\\QOwnNotesAPI\\Controller\\NoteApiController")
                              1. .../AppFramework/DependencyInjection/DIContainer.php line 493
                                 OC\AppFramework\Utility\SimpleContainer->query("OCA\\QOwnNotesAPI\\Controller\\NoteApiController")
                              2. .../DependencyInjection/DIContainer.php line 465
                                 OC\AppFramework\DependencyInjection\DIContainer->queryNoFallback("OCA\\QOwnNotesAPI\\Controller\\NoteApiC ... r")
                              3. lib/private/AppFramework/App.php line 162
                                 OC\AppFramework\DependencyInjection\DIContainer->query("OCA\\QOwnNotesAPI\\Controller\\NoteApiController")
                              4. lib/private/Route/Router.php line 315
                                 OC\AppFramework\App::main(
                                   "OCA\\QOwnNotesAPI\\Controller\\NoteApiController",
                                   "getAppInfo",
                                   ["OC\\AppFramework\\DependencyInjection\\DIContainer"],
                                   ["qownnotesapi.note_api.get_app_info"]
                                 )
                              5. lib/base.php line 1058
                                 OC\Route\Router->match("\/apps\/qownnotesapi\/api\/v1\/note\/app_info")
                              6. index.php line 36
                                 OC::handleRequest(

                                 )

is there something else you need me to do here?

fyrfli avatar Jun 14 '23 22:06 fyrfli

No, just try https://github.com/nextcloud/server/issues/38797#issuecomment-1591046947. 😁

...restarting your Nextcloud containers should do the job.

pbek avatar Jun 15 '23 05:06 pbek

Then it might be the autoload cache in apcu (if this is enabled) where the webserver restart would clear the cache.

I do not think that Nextcloud uses the APCu caching in Composer https://getcomposer.org/doc/articles/autoloader-optimization.md#optimization-level-2-b-apcu-cache. We don't use "apcu-autoloader": true.

ChristophWurst avatar Jun 15 '23 09:06 ChristophWurst

We at least set it on the server autoloader since https://github.com/nextcloud/server/pull/35223 in https://github.com/nextcloud/server/blob/918859cafdbb1c0439e34e75d6d1d5c74160c3d7/lib/base.php#L611

What I'm not sure about is if or how this could interfere with autoloaders that apps provide when shipping their own autoload.php file

https://github.com/nextcloud/server/blob/9f1d497a0b4dbda86e676a3a55758bc2909cc781/lib/private/legacy/OC_App.php#L158

juliusknorr avatar Jun 15 '23 10:06 juliusknorr

Excellent question. This app does not have its own autoloader. So a change of the app class paths wouldn't invalidate when the app updates because the server version mtime stays the same.

Your original observation in https://github.com/nextcloud/calendar/issues/5191#issuecomment-1567926928 makes sense now.

ChristophWurst avatar Jun 15 '23 10:06 ChristophWurst

I think we might want to revert the part about adding the apcu autoloader prefix, as with apcu there is no way we can relibaly invalidate the cache as for example cli and web cache would not be shared, so an upgrade on either of the two would lead to an outdated autoloader in the other.

Also we cannot take the app versions into account for the prefix that early in the execution flow.

The only option I see is that we probably could defer the cache prefix setting to a later point in time when we have a full list of enabled apps and versions similar to the prefix for memcache: https://github.com/nextcloud/server/blob/a2afc7b6a9b42598cadcc3d3e9dde80e0a8a9ce4/lib/private/Server.php#L753

juliusknorr avatar Jun 15 '23 10:06 juliusknorr

I would also vote for reverting the apcu autoloader prefix 👍

szaimen avatar Jun 15 '23 11:06 szaimen

Should be fixed by https://github.com/nextcloud/server/pull/40349 (shipped on 27.1.0 and 26.0.7)

solracsf avatar Sep 16 '23 07:09 solracsf