Errno::ENOMEM: Cannot allocate memory

AI-generated summary

Users are encountering an Errno::ENOMEM: Cannot allocate memory error during Discourse updates, specifically when gzip tries to compress assets. The issue appears to stem from insufficient memory or swap space, even on systems with 2GB RAM. Falco and sam recommend adding swap space as a general fix, linking to a guide on creating a swapfile. avorio confirmed the error and shared free -m output showing 0 swap, and later reported success after adding swap. SkritterJosh and dylanh724 also experienced the error but found the update appeared successful afterward — possibly a false positive. SkritterJosh shared manual update steps via terminal: apt-get update && apt-get upgrade lxc-docker for Docker and git pull && ./launcher rebuild app for Discourse. sam notes that lxc-docker should be replaced with docker-engine, and codinghorror adds that lxc-docker can only be upgraded to 1.9.1. To verify updates, users can check /admin or the page source for version hashes as suggested by Falco.

I just ran an update and got the following error. Then when I refreshed the page to run it again it showed that the update had already been applied. Any thoughts?

Errno::ENOMEM: Cannot allocate memory - gzip -f -c -7 /var/www/discourse/public/assets/docker-manager-app-5abf141467f1e67d5d860236f75651be.js > /var/www/discourse/public/assets/docker-manager-app-5abf141467f1e67d5d860236f75651be.js.gz
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.6/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.6/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/var/www/discourse/lib/tasks/assets.rake:108:in `gzip'
/var/www/discourse/lib/tasks/assets.rake:161:in `block (4 levels) in '
/var/www/discourse/lib/tasks/assets.rake:125:in `call'
/var/www/discourse/lib/tasks/assets.rake:125:in `block in concurrent?'
/var/www/discourse/lib/tasks/assets.rake:152:in `call'
/var/www/discourse/lib/tasks/assets.rake:152:in `block (3 levels) in '
/var/www/discourse/lib/tasks/assets.rake:141:in `each'
/var/www/discourse/lib/tasks/assets.rake:141:in `block (2 levels) in '
/var/www/discourse/lib/tasks/assets.rake:125:in `concurrent?'
/var/www/discourse/lib/tasks/assets.rake:137:in `block in '

Do you have enough ram and swap?

free -m

@SkritterJosh ME TOO!!

2gb droplet - way more than enough. I just saw the update and tried it.

100% same err. Def have enough mem.

@Falco Yes, I do have enough ram and swap.

@dylanh724 I just updated docker and discourse using the terminal and it seemed to work, but using the discourse admin interface it didn’t.

Show us the output of free -m

I got exactly the same error. Here’s the output:

Compressing: docker-manager-app-c32d676193f61b3085ec0e77f8d9fca361291a549828d82d1e33c356786f8ca0.js
gzip /var/www/discourse/public/assets/docker-manager-app-c32d676193f61b3085ec0e77f8d9fca361291a549828d82d1e33c356786f8ca0.js
Bundling assets
Compressing Javascript and Generating Source Maps
rake aborted!
Errno::ENOMEM: Cannot allocate memory - gzip -f -c -7 /var/www/discourse/public/assets/docker-manager-app-c32d676193f61b3085ec0e77f8d9fca361291a549828d82d1e33c356786f8ca0.js > /var/www/discourse/public/assets/docker-manager-app-c32d676193f61b3085ec0e77f8d9fca361291a549828d82d1e33c356786f8ca0.js.gz
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.6/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.6/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
/var/www/discourse/lib/tasks/assets.rake:108:in `gzip'
/var/www/discourse/lib/tasks/assets.rake:149:in `block (2 levels) in '
/var/www/discourse/lib/tasks/assets.rake:130:in `each'
/var/www/discourse/lib/tasks/assets.rake:130:in `block in '
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

And here’s free -m:

root@xyz:~# free -m
             total       used       free     shared    buffers     cached
Mem:          2000       1586        414         36         63        276
-/+ buffers/cache:       1246        754
Swap:            0          0          0
root@xyz:~#

However, now admin/upgrade says that docker_manager is up to date:

docker_manager (9b59950)

Set up a swap!

Thanks. I just did that.

Is it safe to assume that the upgrade went well, then? Or how do I double-check?

There is the version on /admin, and the version hash on the page source (CTRL+U) that you can check.

@avorio I’m not sure if it’s safe to assume that. I also experienced the same thing where the upgrade failed, but then later it said everything was up to date. I went ahead and manually updated both docker and discourse. It did appear they still had updates perform and the dashboard was producing a false positive on the update.

Hi @SkritterJosh! Thanks for that.

How do I manually update both docker and discourse, please?

On my particular setup using Ubuntu I ran the following commands to get things updated.

Docker:

apt-get update
apt-get upgrade lxc-docker

Discourse

cd /var/discourse
git pull
./launcher rebuild app

see: Install Docker Engine on Ubuntu | Docker Docs

you want docker-engine, lxc-docker should be removed.

I believe lxc-docker can be upgraded to 1.9.1 but no higher.

General solution to this error is adding swap, in some cases you may need a bigger swap