JK Docs
DevOps

Add Swap Memory to Prevent OOM Crashes During Builds

Last updated: 4/20/2026

Why Builds Crash (OOM Error)

Building Next.js projects with Prisma is memory-intensive. If server RAM is full during a build, the Linux kernel kills the process. This results in a 502 Bad Gateway or exit code 255.

Signs of an OOM problem:

  • Build exits with code 255
  • 502 Bad Gateway after deployment
  • Server becomes unresponsive during deploy

Create a 4GB Swap File

Run these commands on your server (via SSH or Coolify's Server Terminal):

# Create a 4GB swap file fallocate -l 4G /swapfile # Restrict permissions (security requirement) chmod 600 /swapfile # Format as swap space mkswap /swapfile # Activate the swap swapon /swapfile # Make swap permanent (survives reboots) echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab

Verify Swap is Active

swapon --show free -h

Restart the Server After OOM

If the server is already unresponsive:

# SSH in and reboot ssh root@your-server-ip reboot

Or use Hetzner Cloud Console → Power → Restart.

After reboot (~2-3 minutes), Coolify and all containers restart automatically.

Monitor Memory During Build

# Watch memory usage live watch -n 2 free -h
JK Docs
New Guide

Categories

DevOpsBackendFrontendDatabaseToolsSecurityDesignSystem Admin
Admin Panel