# Anatomy of a 03:14 UTC Exit Code 137 Crash: How V8 Heaps, Binary Payloads & Default Swappiness Silently Kill AI Agents

- URL: https://nodebudget.dev/guides/anatomy-of-n8n-exit-137-oom-postmortem/
- Author: Yuanqiang Leng (https://github.com/a895047059)
- Updated: 2026-11-26

## TL;DR
`restart: unless-stopped` is not high availability—it just hides the crime scene. When an AI workflow pulls a 15 MB PDF into n8n’s default in-RAM binary buffer, V8 heap + glibc arena overhead triggers Linux’s OOM killer (`SIGKILL` = 128 + 9 = Exit Code 137), dropping in-flight webhooks with zero alert. Fix it permanently with five settings: 2 GB swapfile + `vm.swappiness=10`, `N8N_DEFAULT_BINARY_DATA_MODE=filesystem`, `NODE_OPTIONS=--max-old-space-size=2048`, `EXECUTIONS_DATA_PRUNE=true`, and explicit `mem_limit: 3g`.

## 1. Why "My Uptime Monitor Stayed Green" Is the Most Dangerous Lie in Self-Hosting

Here is how a real production OOM outage happens on an unhardened 2 GB or 4 GB n8n / OpenClaw node. At 03:14 UTC, a scheduled workflow wakes up, fetches six PDFs or scrapes four long HTML pages for an LLM summary, and begins passing base64-encoded binary payloads between nodes. Within three seconds, container RSS crosses the host RAM ceiling.

Linux does not send a polite `SIGTERM` so Node.js can flush state or fire your error-notification workflow. The kernel OOM killer immediately sends `SIGKILL` (signal 9). Docker records Exit Code `128 + 9 = 137`, sees `restart: unless-stopped`, and boots a fresh n8n container four seconds later. Your 60-second HTTP uptime ping never notices a blip. Meanwhile, six customer webhooks vanished mid-flight, Postgres holds orphaned "running" execution rows, and you only find out three days later when a client asks why their leads stopped arriving.

> **Forensic Proof in 10 Seconds**: Before assuming your container has never been OOM-killed, run `dmesg -T | grep -iE "killed process|oom-killer"` and `docker inspect --format "{{.Name}} OOM={{.State.OOMKilled}} Exit={{.State.ExitCode}} Restarts={{.RestartCount}}" $(docker ps -aq)`. Most operators running default Compose templates for 30+ days are shocked to see silent restart counts > 0.

## 2. The 3-Layer Memory Blowup Inside Node.js Containers

Why does a 15 MB PDF crash a container that only uses 420 MB at idle? Because three multipliers stack on top of each other inside a Dockerized Node.js runtime:

- Layer 1 — Default In-Memory Binary Mode: Out of the box, n8n keeps downloaded attachments, audio clips, and scraped payloads in Node.js heap buffers. Passing a 15 MB file through base64 encoding (+33%) and JSON serialization across 3 downstream nodes easily balloons transient memory above 140 MB per execution—multiply by 8 concurrent executions and you burn 1.1 GB in seconds.
- Layer 2 — Unbounded V8 Heap vs Container Cgroup: Without `NODE_OPTIONS=--max-old-space-size=2048`, V8 sizes its garbage-collection ceiling against total host RAM (or aggressively postpones major GC sweeps during bursts), pushing RSS past the cgroup cap before V8 even tries to collect dead objects.
- Layer 3 — Glibc Arena Fragmentation & Zero Swap: Native C++ addons and TLS buffers allocate outside V8 heap. When a 3-second spike hits a server with zero swap, the kernel has literally zero pages it can evict—instant `SIGKILL`.

## 3. Our Own Server’s vm.swappiness=60 Confession (And Why =10 Matters)

Go back and inspect Figure 2 of our Lab Essay #01 (verbatim SSH output from our live Ubuntu 24.04 KVM box). Even with 2.9 GiB of RAM freely available, `/swapfile` already had **339 MiB swapped out**. Why? Because Ubuntu ships with `vm.swappiness = 60`, which tells the kernel to proactively push cold anonymous pages to disk long before RAM is tight.

For a database-backed automation host, `vm.swappiness=60` adds unnecessary disk I/O jitter, while having NO swap at all turns every transient 2-second memory spike into a fatal Exit 137 kill. The sweet spot is creating a 2 GB `/swapfile` AND explicitly tuning `sysctl vm.swappiness=10` (persisted in `/etc/sysctl.d/99-nodebudget-swap.conf`). At `swappiness=10`, PostgreSQL 16 and active V8 pages stay pinned in RAM during normal operation, while `/swapfile` acts purely as a 15-minute airbag absorbing rare binary/browser spikes until V8 garbage collection catches up.

```bash
# 1. Host airbag: 2 GB swapfile + low swappiness (persisted across reboots)
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-nodebudget-swap.conf && sudo sysctl --system

# 2. Container guardrails inside docker-compose.yml (n8n service)
environment:
  - N8N_DEFAULT_BINARY_DATA_MODE=filesystem
  - EXECUTIONS_DATA_PRUNE=true
  - EXECUTIONS_DATA_MAX_AGE=168
  - EXECUTIONS_DATA_PRUNE_MAX_COUNT=25000
  - NODE_OPTIONS=--max-old-space-size=2048
mem_limit: 3g
```

## 4. Provisioning Checklist: Don’t Sabotage Yourself at Checkout

Half of the OOM and TLS support emails I read start before Docker is even installed—picking Ubuntu 20.04 (EOL), choosing a 1 GB RAM promo box to save $15/year, or picking a datacenter across the ocean from your webhook callers. Whenever you spin up a new budget KVM node (such as RackNerd’s WHMCS order flow), standardize on Ubuntu 24.04 LTS, 4 GB RAM minimum for n8n + Postgres 16, and the region closest to your primary APIs (US-East / New York or San Jose).

![Live screenshot of the NodeBudget native dialog showing exact 30-second RackNerd WHMCS checkout settings: Ubuntu 24.04 64-bit, datacenter selection, hostname, and instant SSH setup step](https://nodebudget.dev/assets/screenshots/racknerd-dialog-live.png)
*Figure 2 · 30-Second WHMCS Provisioning Cheat Sheet (Live UI): To remove first-time provisioning mistakes, we built this native <dialog> checkout cheat sheet directly beside the calculator—showing the exact Ubuntu 24.04 LTS OS image and datacenter picks before you paste the 1-Click hardened installer.*

---
Source: NodeBudget (https://nodebudget.dev) · License: CC BY 4.0 · Disclosure: Some outbound links under /go/* earn affiliate commission. As an Amazon Associate I earn from qualifying purchases.