Can't open .txt file from web page

Every now and then I am unable to open a .txt file from my Nextcloud web interface.
The same error occurs with photo files. And this is not always the case. The permissions seem to be fine (checked from the admin account). Any ideas?

Nextcloud version: 28.0.2
Operating system and version: Linux (customized by QNAP) 5.10.60-qnap
Apache or nginx version : nginx/1.24.0
PHP version_: 8.2.16 (cli)

Is this the first time you’ve seen this error? : Y

Steps to replicate it:

  1. create file locally 123.txt, put any text inside
  2. open it from the web interface
  3. got the error:

The output of my Nextcloud log in Admin > Logging:

{
  "reqId": "YhCOLyPHxOkPCScPsYRh",
  "level": 3,
  "time": "2024-02-27T21:16:05+00:00",
  "remoteAddr": "192.168.2.254",
  "user": "nextclouduser",
  "app": "index",
  "method": "PUT",
  "url": "/apps/text/session/128405/create",
  "message": "Exception thrown: OCP\\Files\\GenericFileException",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
  "version": "28.0.2.5",
  "exception": {
    "Exception": "OCP\\Files\\GenericFileException",
    "Message": "",
    "Code": 0,
    "Trace": [
      {
        "file": "/config/www/nextcloud/apps/text/lib/Service/ApiService.php",
        "line": 293,
        "function": "getContent",
        "class": "OC\\Files\\Node\\File",
        "type": "->"
      },
      {
        "file": "/config/www/nextcloud/apps/text/lib/Service/ApiService.php",
        "line": 150,
        "function": "loadContent",
        "class": "OCA\\Text\\Service\\ApiService",
        "type": "->"
      },
      {
        "file": "/config/www/nextcloud/apps/text/lib/Controller/SessionController.php",
        "line": 61,
        "function": "create",
        "class": "OCA\\Text\\Service\\ApiService",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 230,
        "function": "create",
        "class": "OCA\\Text\\Controller\\SessionController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 137,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/App.php",
        "line": 184,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/app/www/public/lib/private/Route/Router.php",
        "line": 315,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/app/www/public/lib/base.php",
        "line": 1069,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/app/www/public/index.php",
        "line": 39,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/app/www/public/lib/private/Files/Node/File.php",
    "Line": 56,
    "message": "",
    "exception": [],
    "CustomMessage": "Exception thrown: OCP\\Files\\GenericFileException"
  },
  "id": "65de511b3e55f"
}

The output of my config.php file in /config/www/nextcloud/config/config.php

<?php
$CONFIG = array (
  'datadirectory' => '/data',
  'instanceid' => 'oc7nlwd2g3ja',
  'passwordsalt' => xxx,
  'secret' => 'HJXT2gj7BdA9DJVEHmPWAMwilx//+WAMuWF14UOjrcnn8Ecp',
  'trusted_domains' =>
  array (
    0 => 'XXX.XX.XXX.XXX',
  ),
  'dbtype' => 'sqlite3',
  'version' => '28.0.2.5',
  'overwrite.cli.url' => 'https://192.168.2.34:9443',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\APCu',
  'upgrade.disable-web' => true,
  'loglevel' => 2,
  'maintenance' => false,
);

This is a highly unusual configuration. I believe you’d be better with no locking memcache than to use APCu for it. While some of the other memcache parameters can reasonably fall back on the one configured for memcache.local (which is often APCu), there’s specific code that avoids that for memcache.locking:

Since your getting errors during file creation time, something broken with your locking config may be the culprit here. You can leaving filelocking.enabled set to true (it’ll use the database as the fallback), but see if you can reproduce this behavior with the memcache.locking line commented out (restart FPM after/before re-testing).

thank you for the quick response!
when i comment this line out, and restart docker (my Nextcloud is running in docker), it restores the same line. So it is the default.
don’t know how to restart just fpm.

Hmm. Restarting the Docker container - as it sounds like you did - should be more than sufficient.

It’s definitely not the coded default in Nextcloud itself. Can you share your Docker Compose file?

here it is (replaced some lines by !!!)

version: “3.7”

services:
  nextcloud:
    image: linuxserver/nextcloud:latest
    container_name: nextcloud
    networks:
      - nextcloudnet
    deploy:
    environment:
      - PUID=1111   # dockeruser id
      - PGID=100    # dockeruser group
      - TZ=!!!
    volumes:
      - /share/ZFS18_DATA/container/nextcloud-data/nextcloud/config:/config
      - /share/ZFS18_DATA/container/nextcloud-data/data:/data
    ports:
      - 9443:443
    restart: unless-stopped
    depends_on:
      - db

  db:
    image: linuxserver/mariadb:latest
    container_name: nextcloud_db
    networks:
      - nextcloudnet
    deploy:
    environment:
      - PUID=1111
      - PGID=100
      - MYSQL_ROOT_PASSWORD=!!! # replace with own password
      - TZ=Asia/Jerusalem
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextclouduser
      - MYSQL_PASSWORD=!!! # replace with own password
    volumes:
      - /share/ZFS18_DATA/container/nextcloud-data:/config
    restart: unless-stopped

networks:
    nextcloudnet:
        driver: bridge
        ipam:
          config:
            - subnet: 10.0.8.0/24
              gateway: 10.0.8.1

Yep, but it seems that the linuxserver guys actually configure it that way in their image. Probably to avoid the warning on the Security & setup warnings page… docker-nextcloud/root/etc/s6-overlay/s6-rc.d/init-nextcloud-config/run at 787055f10096d74c7f21694cf6fc195c1068c841 · linuxserver/docker-nextcloud · GitHub

@Michael_Levin I’m not sure if this causes your issue, but it’s definitely not a recommended configuration (see here and here) and someone should probably tell them by opening an issue on GitHub… https://github.com/linuxserver/docker-nextcloud/issues

I seem to have found that most of the problems occur because I mount external storage using SMB (I don’t understand the reason why, but just as a fact). If I add a line with the path to the storage in the docker nextcloud application configuration, for example:

volumes:
      - /share/ZFS18_DATA/container/nextcloud-data/nextcloud/config:/config
      - /share/ZFS18_DATA/container/nextcloud-data/data:/data
      - /share/ZFS20_DATA/megahoney:/megahoney

and mount the external storage as local, the problems disappeared (except that when creating a new file it also has the residual ‘New Text Document.txt’ - not good, but acceptable)

And it has nothing to do with the config issue you advised me to fix somehow.
As such, I want to install Redis and see what happens.

i changed docker yaml, added Redis service

version: "3.7"
services:
  redis:
    image: redis:7.2-alpine
    restart: always
    container_name: redis
    networks:
      - nextcloudnet

and changed php config:

$CONFIG = array (
  'datadirectory' => '/data',
  'instanceid' => '---',
  'passwordsalt' => '---,
  'secret' => '---',
  'trusted_domains' =>
  array (
    0 => '---',
  ),
  'dbtype' => 'sqlite3',
  'version' => '28.0.2.5',
  'overwrite.cli.url' => 'https://192.168.2.38:9443',
  'installed' => true,
  'filelocking.enabled' => true,
  'upgrade. Disable-web' => true,
  'loglevel' => '3',
  'maintenance' => false,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' => [
     'host' => 'redis',
  ],
);

Now on external storage when mounted using SMB I get the following errors when adding a file to any location

{
  "reqId": "3DsIpeMRDxZomb5U5APH",
  "level": 3,
  "time": "2024-02-28T20:33:53+00:00",
  "remoteAddr": "192.168.2.254",
  "user": "a.pilipchuk",
  "app": "no app in context",
  "method": "POST",
  "url": "/ocs/v2.php/apps/files/api/v1/templates/create",
  "message": "Invalid path",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
  "version": "28.0.2.5",
  "exception": {
    "Exception": "OCP\\Files\\GenericFileException",
    "Message": "Invalid path",
    "Code": 0,
    "Trace": [
      {
        "file": "/config/www/nextcloud/apps/files/lib/Controller/TemplateController.php",
        "line": 80,
        "function": "createFromTemplate",
        "class": "OC\\Files\\Template\\TemplateManager",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 230,
        "function": "create",
        "class": "OCA\\Files\\Controller\\TemplateController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 137,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/app/www/public/lib/private/AppFramework/App.php",
        "line": 184,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/app/www/public/lib/private/Route/Router.php",
        "line": 315,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/app/www/public/ocs/v1.php",
        "line": 65,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/app/www/public/ocs/v2.php",
        "line": 23,
        "args": [
          "/app/www/public/ocs/v1.php"
        ],
        "function": "require_once"
      }
    ],
    "File": "/app/www/public/lib/private/Files/Template/TemplateManager.php",
    "Line": 159,
    "message": "Invalid path",
    "exception": [],
    "CustomMessage": "Invalid path"
  },
  "id": "65df98b5234cd"
}