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

[Bug]: Downloads fail at 4GB with error "server returned wrong content-range" with 32bit server #39923

Closed
5 of 8 tasks
cbartondock opened this issue Aug 17, 2023 · 13 comments · Fixed by #40501
Closed
5 of 8 tasks
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: 32bits Bug specific to 32bits architectures

Comments

@cbartondock
Copy link

⚠️ This issue respects the following points: ⚠️

Bug description

All downloads from the server fail at around 4GB, and on the sync client it gives the error "server returned wrong content-range." I have verified that the problem is not with apache/php configuration or my external storage (downloading large files from the same raid array via apache directly works just fine) and that it isn't my router configuration (it also fails in exactly the same way when http://localhost/nextcloud/remote.php/webdav addresses are used). I have also tried several client devices so it is definitely a server side issue.

Based on the fact that it always fails around 4GB I have to conclude that it is my Pi 4's 32bit OS causing the issue - I know that support for 32bit servers was only recently re-introduced to Nextcloud. Interestingly uploads work fine.

It is possible this is a regression that has re-introduced the bug in issue 5031, it certainly seems to be caused by the file sizes being incorrect (most probably those returned by the stat function in lib/private/Files/Storage/Dav.php).

Doing an occ files:scan does actually correct some but not all of the file sizes displayed in the web app, but it doesn't fix the issue with downloads. I should also note that in order to even get occ files:scan to run without error on Nextcloud 27 I had to patch in the typecasts suggested here.

Neither nextcloud logs nor APACHE/PHP-FPM logs have any errors.

Steps to reproduce

  1. Install Nextcloud 27 on a 32bit server.
  2. Try to download or sync
  3. Fails at around 4GB

Expected behavior

Downloads of all file sizes up to PHP/APACHE limits suceed.

Installation method

Community Manual installation with Archive

Nextcloud Server version

27

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database engine version

MariaDB

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

Upgraded to a MAJOR version (ex. 22 to 23)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?

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

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "localhost"
        ],
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "27.1.0.0",
        "overwrite.cli.url": "http:\/\/localhost",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauth": 1,
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "default_locale": "en_US",
        "default_phone_region": "US",
        "overwritehost": "cloud.cbartondock.mywire.org",
        "overwriteprotocol": "https",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "maintenance": true,
        "theme": "",
        "loglevel": 2,
        "updater.release.channel": "beta",
        "updater.secret": "***REMOVED SENSITIVE VALUE***"
    }
}

List of activated Apps

Enabled:
  - activity: 2.19.0
  - circles: 27.0.1
  - cloud_federation_api: 1.10.0
  - comments: 1.17.0
  - contactsinteraction: 1.8.0
  - dashboard: 7.7.0
  - dav: 1.27.0
  - federatedfilesharing: 1.17.0
  - federation: 1.17.0
  - files: 1.22.0
  - files_pdfviewer: 2.8.0
  - files_reminders: 1.0.0
  - files_rightclick: 1.6.0
  - files_sharing: 1.19.0
  - files_trashbin: 1.17.0
  - files_versions: 1.20.0
  - firstrunwizard: 2.16.0
  - logreader: 2.12.0
  - lookup_server_connector: 1.15.0
  - nextcloud_announcements: 1.16.0
  - notifications: 2.15.0
  - oauth2: 1.15.1
  - password_policy: 1.17.0
  - photos: 2.3.0
  - privacy: 1.11.0
  - provisioning_api: 1.17.0
  - recommendations: 1.6.0
  - related_resources: 1.2.0
  - serverinfo: 1.17.0
  - settings: 1.9.0
  - sharebymail: 1.17.0
  - support: 1.10.0
  - survey_client: 1.15.0
  - systemtags: 1.17.0
  - text: 3.8.0
  - theming: 2.2.0
  - twofactor_backupcodes: 1.16.0
  - updatenotification: 1.17.0
  - user_status: 1.7.0
  - viewer: 2.1.0
  - weather_status: 1.7.0
  - workflowengine: 2.9.0
Disabled:
  - admin_audit: 1.17.0
  - bruteforcesettings: 2.7.0
  - encryption: 2.15.0
  - files_external: 1.19.0
  - suspicious_login: 5.0.0
  - twofactor_totp: 9.0.0
  - user_ldap: 1.17.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

Empty

Additional info

PHP 8.1.21
Nextcloud 27.1.0 beta 1
Raspbian/Debian Bullseye

@cbartondock cbartondock added 0. Needs triage Pending check for reproducibility or if it fits our roadmap bug labels Aug 17, 2023
@joshtrichards
Copy link
Member

Hi @cbartondock - Any idea what NC release you were most recently running where this behavior did not occur?

Also, for completeness, are you running the 64-bit kernel with 32-bit user land which became the new default behavior on 64-bit Pi boards a few months back? (i.e. raspberrypi/firmware#1795 (comment))

@joshtrichards
Copy link
Member

joshtrichards commented Aug 19, 2023

Stack trace provided by third party in the linked thread for occ:

Starting scan for user 1 out of 6 (gebruiker1)
An unhandled exception has been thrown:
TypeError: OC\Files\Cache\Scanner::scanChildren(): Argument #6 ($oldSize) must be of type int, float given, called in /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php on line 347 and defined in /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php:391
Stack trace:
#0 /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php(347): OC\Files\Cache\Scanner->scanChildren()
#1 /var/www/html/nextcloud/lib/private/Files/Utils/Scanner.php(269): OC\Files\Cache\Scanner->scan()
#2 /var/www/html/nextcloud/apps/files/lib/Command/Scan.php(164): OC\Files\Utils\Scanner->scan()
#3 /var/www/html/nextcloud/apps/files/lib/Command/Scan.php(219): OCA\Files\Command\Scan->scanFiles()
#4 /var/www/html/nextcloud/3rdparty/symfony/console/Command/Command.php(298): OCA\Files\Command\Scan->execute()
#5 /var/www/html/nextcloud/core/Command/Base.php(177): Symfony\Component\Console\Command\Command->run()
#6 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(1040): OC\Core\Command\Base->run()
#7 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#8 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#9 /var/www/html/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#10 /var/www/html/nextcloud/console.php(100): OC\Console\Application->run()
#11 /var/www/html/nextcloud/occ(11): require_once('...')

@cbartondock
Copy link
Author

cbartondock commented Aug 19, 2023

Unfortunately no, I only recently (on Nextcloud 24) attempted to download a large file (and it failed in exactly the same way). It may have worked in earlier versions or not. Running uname -a gives

Linux Spock 6.1.45-v8+ #1671 SMP PREEMPT Fri Aug 11 14:49:25 BST 2023 aarch64 GNU/Linux

So I think that indeed the kernel is 64bit (I update the firmware regularly). The OS is definitely 32 bit, however, as at the time I originally installed it (Raspbian Jessi) there were no 64bit raspbian images. Running getconf LONG_BIT yields 32 as expected.

@cbartondock
Copy link
Author

It may also be relevant that the data directory is on a raid array I haven't tested it yet with the data directory on the sd card.

@joshtrichards joshtrichards added the feature: 32bits Bug specific to 32bits architectures label Aug 19, 2023
@kesselb
Copy link
Contributor

kesselb commented Aug 19, 2023

Possible patch:

Index: lib/private/Files/Cache/Scanner.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/private/Files/Cache/Scanner.php b/lib/private/Files/Cache/Scanner.php
--- a/lib/private/Files/Cache/Scanner.php	(revision 4a671bc7d18fcd97971fd5805e5f1a723e8a0860)
+++ b/lib/private/Files/Cache/Scanner.php	(date 1692461787019)
@@ -385,10 +385,10 @@
 	 * @param int $reuse a combination of self::REUSE_*
 	 * @param int $folderId id for the folder to be scanned
 	 * @param bool $lock set to false to disable getting an additional read lock during scanning
-	 * @param int $oldSize the size of the folder before (re)scanning the children
+	 * @param int|float $oldSize the size of the folder before (re)scanning the children
 	 * @return int|float the size of the scanned folder or -1 if the size is unknown at this stage
 	 */
-	protected function scanChildren(string $path, $recursive, int $reuse, int $folderId, bool $lock, int $oldSize) {
+	protected function scanChildren(string $path, $recursive, int $reuse, int $folderId, bool $lock, int|float $oldSize) {
 		if ($reuse === -1) {
 			$reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : self::REUSE_ETAG;
 		}

@cbartondock
Copy link
Author

I will try the patch and do an occ files:scan and re-attempt to download files

@cbartondock
Copy link
Author

Is it actually correct that it should be getting a value passed in as a float? That doesn't seem right for a file size which I assume is in bytes.

@cbartondock
Copy link
Author

So that patch fixed the issue with file / folder sizes showing up as incorrect in the web app, but when I go to download (for example) a 4.3GB file the browser's downloader shows it as 4GB (so clearly the wrong size is being reported) and it fails at 4GB (probably because the two sides disagree on whether or not it should be finished)

@cbartondock
Copy link
Author

Is there a different file where a similar change should be made to the DAV implementation?

@cbartondock
Copy link
Author

I ended up upgrading to 64 bit which solved the issue, but if anyone is interested in debugging this I still have the old OS image and would be happy to help.

@szaimen
Copy link
Contributor

szaimen commented Sep 8, 2023

Cc @come-nc

@come-nc
Copy link
Contributor

come-nc commented Sep 11, 2023

Is it actually correct that it should be getting a value passed in as a float? That doesn't seem right for a file size which I assume is in bytes.

On 32 bits all sizes above 4GB have to be a float because they do not fit in an int.

Do you have a PHP error in the logs with a trace when the download fails at 4GB?

@come-nc
Copy link
Contributor

come-nc commented Sep 25, 2023

Stack trace provided by third party in the linked thread for occ:

Starting scan for user 1 out of 6 (gebruiker1)
An unhandled exception has been thrown:
TypeError: OC\Files\Cache\Scanner::scanChildren(): Argument #6 ($oldSize) must be of type int, float given, called in /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php on line 347 and defined in /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php:391
Stack trace:
#0 /var/www/html/nextcloud/lib/private/Files/Cache/Scanner.php(347): OC\Files\Cache\Scanner->scanChildren()
#1 /var/www/html/nextcloud/lib/private/Files/Utils/Scanner.php(269): OC\Files\Cache\Scanner->scan()
#2 /var/www/html/nextcloud/apps/files/lib/Command/Scan.php(164): OC\Files\Utils\Scanner->scan()
#3 /var/www/html/nextcloud/apps/files/lib/Command/Scan.php(219): OCA\Files\Command\Scan->scanFiles()
#4 /var/www/html/nextcloud/3rdparty/symfony/console/Command/Command.php(298): OCA\Files\Command\Scan->execute()
#5 /var/www/html/nextcloud/core/Command/Base.php(177): Symfony\Component\Console\Command\Command->run()
#6 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(1040): OC\Core\Command\Base->run()
#7 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#8 /var/www/html/nextcloud/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun()
#9 /var/www/html/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#10 /var/www/html/nextcloud/console.php(100): OC\Console\Application->run()
#11 /var/www/html/nextcloud/occ(11): require_once('...')

This one will be fixed by #40501

If anyone encountered another trace, please post it. Either here or in a new ticket if this one is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap 27-feedback bug feature: 32bits Bug specific to 32bits architectures
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants