Cannot upload large files as instance crashes with OutOfMemory

Hi. I deploy a remix app which should support video uploads. I noticed that when uploading files of around 100MB, my instance just dies with these logs:

2024-06-21T23:59:11.429 app[d8913e6f6e17d8] qro [info] [ 51.841459] Out of memory: Killed process 338 (node) total-vm:13230264kB, anon-rss:1879876kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:6300kB oom_score_adj:0

2024-06-21T23:59:11.511 proxy[d8913e6f6e17d8] qro [error] [PU02] could not complete HTTP request to instance: connection error: Connection reset by peer (os error 104)

2024-06-21T23:59:11.513 app[d8913e6f6e17d8] qro [info] Killed

2024-06-21T23:59:12.295 app[d8913e6f6e17d8] qro [info] INFO Main child exited normally with code: 137

2024-06-21T23:59:12.308 app[d8913e6f6e17d8] qro [info] INFO Starting clean up.

2024-06-21T23:59:12.310 app[d8913e6f6e17d8] qro [info] WARN could not unmount /rootfs: EINVAL: Invalid argument

2024-06-21T23:59:12.310 app[d8913e6f6e17d8] qro [info] [ 52.723394] reboot: Restarting system

You might think that my instance ran out of memory but I heavily doubt that. My instance has 2GB and metrics show that it hasn’t used even 500MB. So I don’t think that’s the case.

Does anyone know what else could it be? :pray:

Out of memory: Killed process 338 (node) total-vm:13230264kB, anon-rss:1879876kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:6300kB oom_score_adj:0

This line says that your process (node) ran out of memory and crashed, and at the time it crashed it was taking up 1879876kB (~1.88GB) of memory.

It’s quite possible and even common for an app to consume and run out of memory much more quickly than the 15-second metrics interval can catch.

1 Like

What is weird is that app is usually running at 300MB and uploading a file of 100MB shouldn’t take so much memory… could something be wrong in my app? or is it normal for NodeJS apps to take so much memory?

It is hard to say what is “normal” for a NodeJS app. It runs on a JavaScript engine designed for the Chome browser.

Try experimenting with --max-old-space-size, as described on the following page: Command-line API | Node.js v22.3.0 Documentation

You can also add swap space: Fly Launch configuration (fly.toml) · Fly Docs

Taken together, Node will reclaim memory before you run out, and provide a buffer in case it is needed. Garbage collection and swap space impact performance, but in general that’s preferred over crashing.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.