How to Permanently Fix n8n 502 Bad Gateway, OOM Kills & SQLite Database Locks
DEPLOYCALC SIZING VERDICT: DEPLOYCALC HOW TO PERMANENTLY FIX N8N
/etc/docker/daemon.json • Fix Lock • DeployCalcHostinger 16GB KVM — Fix Lock
16GB DDR5 NVMe for Fix Lock — auto-discount + 30d refund
Vultr NVMe — Fix Lock
Low-RTT Singapore/Tokyo Vultr node for Fix Lock (18 ms)
InterServer Price-Lock — Fix Lock
Flat renewal price-lock slice for Fix Lock (12–28 containers)
If your self-hosted n8n instance randomly throws 502 Bad Gateway behind Caddy/Nginx or freezes during concurrent webhook bursts, one of three bottlenecks is hitting your container.
Key Engineering Takeaways
- Error #1 (OOM Kill / Exit Code 137): Node.js V8 heap exceeds physical RAM without a 4GB NVMe swapfile.
- Error #2 (SQLITE_BUSY): Default SQLite single-writer locking collapses when 5+ webhooks fire simultaneously — migrate to PostgreSQL 16.
- Error #3 (Unbounded Heap): Always set NODE_OPTIONS=--max-old-space-size matched to 50%–60% of your VPS RAM.
1. Confirming Whether Linux OOM-Killed Your n8n Container — DeployCalc
Run docker inspect n8n --format="{{.State.OOMKilled}} {{.State.ExitCode}}" or dmesg -T | grep -i oom. If you see ExitCode 137, your reverse proxy shows 502 Bad Gateway simply because the n8n container was forcibly terminated by the Linux kernel.
Adding a 4GB NVMe swapfile with vm.swappiness=10 absorbs brief Puppeteer/AI memory spikes, while upgrading from a 2GB–4GB droplet to an 8GB KVM NVMe node eliminates daily swap thrashing.
docker inspect $(docker ps -aqf "name=n8n") --format='OOMKilled={{.State.OOMKilled}} Exit={{.State.ExitCode}}'
# Inside docker-compose.yml environment for an 8GB RAM VPS:
# - NODE_OPTIONS=--max-old-space-size=4096
# - EXECUTIONS_DATA_PRUNE=true
# - EXECUTIONS_DATA_MAX_AGE=1682. Eliminating SQLITE_BUSY Locks With PostgreSQL 16 — DeployCalc
SQLite writes the entire database file lock on every workflow step transition. When parallel sub-workflows or Slack/Stripe webhooks arrive at the same millisecond, tasks stall and queue memory balloons.
Switching DB_TYPE=postgresdb with PostgreSQL 16 Alpine handles hundreds of concurrent writes cleanly while keeping idle database RAM under 250MB.
3. Generate a Pre-Tuned Compose Stack in 10 Seconds — DeployCalc
Instead of hand-editing YAML indentation, open our n8n Production Calculator to auto-generate a verified Caddy Auto-SSL + PostgreSQL 16 + Swap-protected setup matched to your exact workflow count.
Technical Sizing FAQ
What should max-old-space-size be on an 8GB VPS?
Set NODE_OPTIONS=--max-old-space-size=4096 (4GB) on an 8GB VPS so Ubuntu OS, PostgreSQL 16, and Caddy always retain 4GB of clean breathing room.
Related Setup Playbooks
How to Self-Host n8n on Hostinger VPS in 60s (No-Code 2026)
Step-by-step 2026 guide to self-hosting unlimited n8n AI workflows on Hostinger KVM 2 VPS using the official 1-Click template—zero Linux CLI needed.
LiteSpeed Web Hosting vs KVM VPS for WordPress (2026 Guide)
Should you run WordPress & WooCommerce on Managed LiteSpeed Business Hosting or an unmanaged KVM VPS? Compare TTFB, cost, and maintenance.
Host a 24/7 Minecraft or Palworld Server (Zero Port Forward)
Launch a lag-free 24/7 modded Minecraft, Cobblemon, ATM10, or Palworld server in 3 minutes using a pre-installed AMP Game Panel VPS—no router port forwarding.
High-Freq EPYC vs Shared KVM: How to Permanently Fix n8n 502 Bad
Ahead of peak concurrency bursts on How to Permanently Fix n8n 502, setting systemd MemoryHigh=82% soft throttling on Fix n8n processes stops Linux OOM-Killer resets before OOM Crash host tiers sessions drop.
To hold 18 ms write latency on How to Permanently Fix n8n 502, tuning vm.dirty_ratio=10 around Fix n8n processes flush queues sustains 95,000 IOPS throughput under peak OOM Crash host tiers writes.
Over APAC subsea routes serving How to Permanently Fix n8n 502, keeping Fix n8n processes stack configs portable between Hostinger and Vultr holds end-to-end 18 ms targets across OOM Crash host tiers routes.
# RSS & swap probe for fix-n8n-oom-crash-502-sqlite-lock
free -m && vmstat 1 4
ps -eo pid,rss,comm --sort=-rss | head -n 8
# /etc/docker/daemon.json: default-ulimits nofile=65536
| Fix n8n OOM Stage | Load (containers) | Cap (/etc/docker/daemon.json) | DeployCalc Host Fit |
|---|---|---|---|
| Baseline — Fix n8n OOM | 12 containers | 8GB + 4GB swap | 8GB NVMe (~$5.99/mo) |
| Production — Fix n8n OOM | 28 containers | 16GB + default-ulimits nofile=65536 | Hostinger ($10.49/mo, 95,000 IOPS) |
| Peak — Fix n8n OOM | 64 containers | 32GB (18 ms) | Vultr ($12.00/mo, isolated dockerd) |
Against noisy-neighbor contention around How to Permanently Fix n8n 502, allocating non-oversold EPYC threads to Fix n8n processes ($10.49/mo) avoids burstable CPU credit cliffs on 24/7 OOM Crash host tiers nodes.
During scheduled archive windows on How to Permanently Fix n8n 502, validating Fix n8n processes (Overlay2 NVMe 4K) checksums before rotating snapshots lets lean teams run OOM Crash host tiers with audit-ready RPO guarantees.
Acceptance Checklist & Operator Q&A: How to Permanently Fix n8n 502 Bad
- Pin How to Permanently Fix n8n 502 compute onto dedicated EPYC cores keeping L3 cache locality sharp across Fix n8n processes threads.
- Verify archive checksums on How to Permanently Fix n8n 502 (4K random write) proving <8-minute disaster recovery across OOM Crash host tiers.
- Scan exposed IPv4/IPv6 ports before How to Permanently Fix n8n 502 launch hiding OOM Crash host tiers daemon ports from automated scanners.
- Model 36-month Hostinger ($10.49/mo) TCO for How to Permanently Fix n8n 502 anchoring predictable $10.49/mo OPEX as OOM Crash host tiers grows.
When should How to Permanently Fix n8n 502 Bad step from 16GB to 32GB on DeployCalc?
Under Linux pagecache pressure around How to Permanently Fix n8n 502, preserving kernel pagecache buffers around hot Fix n8n processes tables eliminates swap storms across OOM Crash host tiers (28 containers).
How can DeployCalc teams version and test /etc/docker/daemon.json for How to Permanently Fix n8n 502 Bad?
To eliminate unauthorized port exposure on How to Permanently Fix n8n 502, binding internal Fix n8n processes (Coolify Traefik) sockets strictly to 127.0.0.1 streamlines OOM Crash host tiers incident triage with clean audit logs.
Where should staging vs production How to Permanently Fix n8n 502 Bad nodes live (Hostinger vs Vultr)?
As teams move How to Permanently Fix n8n 502 off per-seat SaaS billing, benchmarking Fix n8n processes load on hourly Vultr ($12.00/mo) first aligns OOM Crash host tiers infrastructure spend cleanly with actual load.
DeployCalc How to Permanently Fix n8n: NVMe IOPS vs Rate (95,000 IOPS)
DeployCalc Resilience Path (DeployCalc How to Permanently Fix n8n)
[+] Why This Spec Works for Fix n8n OOM (DeployCalc)
- Shields DeployCalc How to Permanently Fix n8n from neighbor RAM steal near 28 containers.
- Sustains 95,000 IOPS on DeployCalc How to Permanently Fix n8n writes, holding 18 ms.
- Swaps variable DeployCalc How to Permanently Fix n8n seat bills for flat $10.49/mo OPEX.
[-] Operational Caveats on Fix n8n OOM (DeployCalc)
- Multi-year checkout unlocks $10.49/mo unit pricing for DeployCalc How to Permanently Fix n8n.
- Your team owns /etc/docker/daemon.json tuning and backups around DeployCalc How to Permanently Fix n8n.
Deploy This Spec for Fix n8n OOM (DeployCalc) If
- Production DeployCalc How to Permanently Fix n8n workloads needing 18 ms with <1.5% steal.
- Sysadmins needing root on DeployCalc How to Permanently Fix n8n to enforce default-ulimits nofile=65536.
Avoid Annual Prepay on Fix n8n OOM (DeployCalc) If
- One-off DeployCalc How to Permanently Fix n8n rehearsals under 5 days on hourly instances.
- Orgs launching DeployCalc How to Permanently Fix n8n with nobody watching dockerd backup alerts.
$10.49/mo