[3.8.8+] File downloads are corrupted (contains HTTP headers ?) after switch from Windows to Linux webserver

[3.8.8+] File downloads are corrupted (contains HTTP headers ?) after switch from Windows to Linux webserver

Jeff Noel -
回帖数:4

We've been trying to debug this for the last couple of days. Our users can upload just fine, but files above 10Mb get corrupted whenever they try to download them.

We've been trying several things around filelib.php:2233 

if ($filesize > 10000000) {
        // for large files try to flush and close all buffers to conserve memory
        while(@ob_get_level()) {
            if (!@ob_end_flush()) {
                break;
            }
        }
    }

Even though these parts seem to be the issue for us, I'm convinced there has to be a setting, a parameter missing to our Linux config (RHEL 8 / PHP 7.4.16) that is causing this problem.

See the content of a .docx file below: 




We have temporarily bypassed the ob_flush loop and we've been buffering the whole file contents to be able to output uncorrupted files, but for our server's sanity, this isn't the best solution long term. We've been trying to fix our setup on a development instance, without success.

I've tried searching on Google, StackOverflow and on the Moodle forums for a similar issue, without success. Has anyone encountered this issue before ?

If I look at the file directly in the moodledata directory, it is NOT corrupted and can work just fine if I add the correct file extension to it.

This issue happens for pretty much all our documents above 10Mb, and right now unoconv file conversion is not activated, so it should not be the source of the problem. This issue was not happening on our Windows web server.

If anyone has a clue / needs more info, feel free to tell/ask. 

Thank you in advance everyone.

回复Jeff Noel

Re: [3.8.8+] File downloads are corrupted (contains HTTP headers ?) after switch from Windows to Linux webserver

Ken Task -
Particularly helpful Moodlers的头像

You might be chasin' some rabbits with unoconv ... python that just converts files via LibreOffice in headless mode/listener to PDF's ... shouldn't alter original docx - so that's a rabbit hole.

What's:

php -i |grep max_input_vars
php -i |grep upload_max_filesize
php -i |grep post_max_size

look like?

Got any antivirus checking?

You might install apache2buddy ... a pl script ... and run it ...

You've not said if you have an all in one Linux server or not.

'SoS', Ken


回复Ken Task

Re: [3.8.8+] File downloads are corrupted (contains HTTP headers ?) after switch from Windows to Linux webserver

Jeff Noel -


Update: We found the issue

It is related to cifs mounts FROM Linux TO a Windows share in the Linux kernel : https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=900821 
Explicitely declaring cache=none in our fstab mount options for the moodledata share solved the issue.

Sorry for the trouble, I was sure it was some PHP/Apache config playing with us. Turns out it's the kernel itself when it comes to Linux/Windows shares.

----

$ php -i | grep max_input_var
max_input_vars => 1000 => 1000

$ php -i | grep upload_max_filesize
upload_max_filesize => 2048M => 2048M

$ php -i | grep post_max_size
post_max_size => 2048M => 2048M


No antivirus active on the dev VM in particular (deactivated to debug this issue - didn't affect the file ouput). 

What do you mean by all in one server ? 
This is a RHEL 8.3 Web server running Apache dedicated only to this Moodle instance. On top of my head the web server has something like a dedicated 8 or 16 core with 32Gb RAM.
The database and moodledata are hosted on a windows server since we are planning on moving moodle to a Kubernetes configuration with multiple web server instances.

I ran apache2buddy, nothing specific came out of the ordinary except we don't have Python 2 installed since the OS comes with Python3 by default (RHEL 8.3).
Thanks for the heads up on that though, I'll keep apache2buddy in my toolbox!

-----

Here's our Zlib setup (compression deactivated):

Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate    
zlib.output_compression => Off => Off  
zlib.output_compression_level => -1 => -1
zlib.output_handler => no value => no value


回复Jeff Noel

Re: [3.8.8+] File downloads are corrupted (contains HTTP headers ?) after switch from Windows to Linux webserver

Ken Task -
Particularly helpful Moodlers的头像

"What do you mean by all in one server ?"

Apache + code + DB server (thus DB for moodle) + moodledata on *same* machine.   Uhhhh ... you didn't share setup info so how was anyone able to guess your setup.

Since the code is on a Linux flavored box, config to other flavored servers for moodledata is (as you have discovered) a factor.  DB should also be considered in that light.

Since DB is also hosted on another OS/platform, dunno that following would work as well, but another 'tool' is MySQLTuner.   A perl script for checking out MySQL/MariaDB.

https://github.com/major/MySQLTuner-perl

Run from web server to DB server is very true to how your site is to function and involves networking ... the layer below but comes before application (ie, the moodle).

'SoS', Ken