openbmc / bmcweb

A do everything Redfish, KVM, GUI, and DBus webserver for OpenBMC
Apache License 2.0
160 stars 131 forks source link

can not upload large file to sd card (for example : file size 800M) #232

Closed lzy1212003 closed 2 years ago

lzy1212003 commented 2 years ago

Describe the bug When uploading a large file(The file size is larger than the embedded system memory), the bmcweb process exits because the memory request fails

Environment linux embedded system df Filesystem 1K-blocks Used Available Use% Mounted on dev 220092 0 220092 0% /dev tmpfs 245960 62508 183452 25% /run ... tmpfs 245960 344 245616 0% /dev/shm tmpfs 245960 0 245960 0% /sys/fs/cgroup tmpfs 245960 8 245952 0% /tmp tmpfs 245960 12 245948 0% /var/volatile /dev/mmcblk0p1 2093048 4 2093044 0% /mnt

uname -a Linux eeff55ab 5.1.5-yocto-s-dirty-f8ff036 #1 Wed Jan 19 13:38:49 UTC 2022 armv6l GNU/Linux

What specific OpenBMC versions (SHA1) did you use? (note, SHA1 should be resolvable to https://github.com/openbmc/openbmc)

To Reproduce Steps to reproduce the behavior: 1、modify meson_options.txt option('http-body-limit', type: 'integer', min : 0, max : 2048, value : 1024, description : 'Specifies the http request body length limit') 2、mount sd card /mnt the capacity of sd card is 4G 3、upload 800M image file to /mnt through rest interface

Jan 20 07:57:11 N/A bmcweb[10838]: terminate called after throwing an instance of 'std::bad_alloc' Jan 20 07:57:11 N/A bmcweb[10838]: what(): std::bad_alloc Jan 20 07:57:11 N/A systemd[1]: bmcweb.service: Main process exited, code=killed, status=6/ABRT Jan 20 07:57:11 N/A systemd[1]: bmcweb.service: Failed with result 'signal'.

reason: when upload files, doRead will call boost::beast::http::async_read,This function writes the contents of the file into embedded system memory until the memory malloc fails

Is this a regression Has this behavior worked in the past? If yes, on which commit did it work, and what commit was broken?

it does not work on any commit

edtanous commented 2 years ago

Considering that you've completely bypassed the protections intended to solve this problem in step 1, this doesn't really qualify as a bug. bmcweb as it exists today is not capable of handling file uploads greater than available ram, and intentionally has limits put in place to ensure that it doesn't crash when those limits are exceeded. If you're interested in improving this, patches are welcome, but for the moment, this is working as designed. The defaults on http-body-limit are supposed to be set to a small fraction (10%) of your available system ram, which you've ignored here.