nextcloud / nextcloud/server

[Bug]: Weird state in appdata, incorrect return type handling

Open
#41,645 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 28-feedback bug feature: apps management
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

Likely related to: https://github.com/nextcloud/server/issues/38761

After running tests locally, I end up with a wiped appdata from time to time.

Visiting the app store greets me with a friendly:

Screenshot from 2023-11-21 17-28-29

{
  "reqId": "YvlS81wDtRf9uV5nQ1v5",
  "level": 3,
  "time": "2023-11-21T16:27:23+00:00",
  "remoteAddr": "172.19.0.1",
  "user": "admin",
  "app": "index",
  "method": "GET",
  "url": "/index.php/settings/apps",
  "message": "Exception thrown: OCP\\Files\\GenericFileException",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
  "version": "28.0.0.6",
  "exception": {
    "Exception": "OCP\\Files\\GenericFileException",
    "Message": "",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/html/lib/private/Files/SimpleFS/SimpleFile.php",
        "line": 74,
        "function": "getContent",
        "class": "OC\\Files\\Node\\File",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/lib/private/App/AppStore/Fetcher/Fetcher.php",
        "line": 166,
        "function": "getContent",
        "class": "OC\\Files\\SimpleFS\\SimpleFile",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/lib/private/App/AppStore/Fetcher/AppFetcher.php",
        "line": 187,
        "function": "get",
        "class": "OC\\App\\AppStore\\Fetcher\\Fetcher",
        "type": "->",
        "args": [
          false
        ]
      },
      {
        "file": "/var/www/html/lib/private/Installer.php",
        "line": 423,
        "function": "get",
        "class": "OC\\App\\AppStore\\Fetcher\\AppFetcher",
        "type": "->",
        "args": [
          false
        ]
      },
      {
        "file": "/var/www/html/apps/settings/lib/Controller/AppSettingsController.php",
        "line": 154,
        "function": "isUpdateAvailable",
        "class": "OC\\Installer",
        "type": "->",
        "args": [
          "files_versions"
        ]
      },
      {
        "file": "/var/www/html/apps/settings/lib/Controller/AppSettingsController.php",
        "line": 137,
        "function": "getAppsWithUpdates",
        "class": "OCA\\Settings\\Controller\\AppSettingsController",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 230,
        "function": "viewApps",
        "class": "OCA\\Settings\\Controller\\AppSettingsController",
        "type": "->",
        "args": []
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 137,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          [
            "OCA\\Settings\\Controller\\AppSettingsController"
          ],
          "viewApps"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 184,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          [
            "OCA\\Settings\\Controller\\AppSettingsController"
          ],
          "viewApps"
        ]
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 315,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\Settings\\Controller\\AppSettingsController",
          "viewApps",
          [
            "OC\\AppFramework\\DependencyInjection\\DIContainer"
          ],
          [
            "",
            "",
            "settings.AppSettings.viewApps"
          ]
        ]
      },
      {
        "file": "/var/www/html/lib/base.php",
        "line": 1069,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/settings/apps"
        ]
      },
      {
        "file": "/var/www/html/index.php",
        "line": 37,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/html/lib/private/Files/Node/File.php",
    "Line": 56,
    "message": "",
    "exception": {},
    "CustomMessage": "Exception thrown: OCP\\Files\\GenericFileException"
  }
}

Steps to reproduce
  1. Clear appdata
  2. Internal server error
  3. 😞
Expected behavior

I assume it's okay that your instance is bricked if you deleted app data.

However, there are also some weird paths in our code.

https://github.com/nextcloud/server/blob/d14d881080e7c994afb5e8b9a03c10e37939f769/lib/private/App/AppStore/Fetcher/Fetcher.php#L183-L186

Above code should handle that situation, a local copy of apps.json does not exist, properly.
It does not because a OCP\Files\GenericFileException is thrown instead of the expected OCP\Files\NotFoundException.

https://github.com/nextcloud/server/blob/8b5997483c852bcee6b44188982073c8213de25f/lib/private/Files/SimpleFS/SimpleFile.php#L80-L95

ISimpleFile.getContent does a check for false.
After https://github.com/nextcloud/server/pull/37943 the method does not return false but throws a OCP\Files\GenericFileException.

Installation method

None

Nextcloud Server version

master

Operating system

Debian/Ubuntu

PHP engine version

Other

Web server

Apache (supported)

Database engine version

None

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?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/private/App/AppStore/Fetcher/Fetcher.php around the local apps.json handling, then inspect lib/private/Files/SimpleFS/SimpleFile.php and the linked change in ISimpleFile::getContent. Reproduce with cleared appdata and follow the AppFetcher path from the provided stack trace. Done means the missing local copy follows the expected NotFoundException path instead of receiving GenericFileException.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.