timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.81k stars 425 forks source link

react-app-rewired build silently exits when not enought memory #463

Closed atomAltera closed 3 years ago

atomAltera commented 4 years ago

I noticed a strange behavior when build docker image. react-app-rewired build exited without emitting files and no sign of error was made by script. Docker just continue to build an image. And only in production I got 404 error because there was lack of index.html and all js files.

I played with docker config and what I have found: If I set Docker's RAM to 1GB and Swap to 510MB, script actually throws out of memory error and build is stopped:

image

But when I set RAM to 2GB (Swap still 512MB) script just exits without error:

image

Here is a listing of ./build/ dir in create docker image:

-rw-r--r--    1 root     root          3150 Jun  4 15:08 favicon.ico
-rw-r--r--    1 root     root          5347 Jun  4 15:08 logo192.png
-rw-r--r--    1 root     root          9664 Jun  4 15:08 logo512.png
-rw-r--r--    1 root     root           492 Jun  4 15:08 manifest.json
-rw-r--r--    1 root     root            67 Jun  4 15:08 robots.txt

And only with 3GB of RAM an images is build successfully:

image

Here is a this project: https://github.com/atomAltera/letmeknow-server The problem is with a package in frontend dir.

I'm using Docker for mac. No other containers was run while building process.

dawnmist commented 3 years ago

Sorry, I hadn't seen this earlier.

The error messages you see are those that webpack provides back to react-scripts to display. React-scripts alters how some of the webpack messages are displayed too - doing things like clearing the screen during the build. If they provide no messages to display, there is nothing react-app-rewired can do about it. :'(

By default, node.js will use up to around 1.4Gb Ram max when building unless you set a parameter to allow it to access more memory. It's possible that the OS inside the docker container is going into a kernel memory panic in the 2Gb Ram version, and auto-killing the webpack/node.js process as the "largest" process running in order to free up memory during the build. If the webpack process is killed, it doesn't get a chance to return log messages for display. You can check if this is the case using sudo dmesg | grep -i “killed process” inside the running container that had been doing a build - if it has occurred, you should get a message line like "host kernel: Out of Memory: Killed process 2592". This blog post has a good description of what the kernel out-of-memory (OOM) killer is and why it is present in the linux kernel at all.