Express API worker OOMKilled when receiving very large JSON body — body-parser buffers whole payload
Environment
Node.js 18.16 running Express 4.18 in Docker containers limited to 1 GiB memory. Route uses express.json() (body-parser) to parse incoming application/json payloads. Clients occasionally upload large JSON payloads (~150–300 MiB).
Symptoms
Process exits without application-level error and container restarts. Orchestration shows container OOMKilled. No stack traces from application-level code are present because Node/V8 is killed by the kernel OOM killer when the heap exceeds available memory.
Observations
docker logs show no uncaughtException; kernel dmesg contains OOM killer killing 'node'. Increasing container memory to 2 GiB temporarily eliminates the crash for the same payload size. Switching the endpoint to a streaming parser (tested in a sandbox) avoids peak memory usage.
Already attempted
Increased container memory limit and set node --max-old-space-size to larger value — mitigates but not viable for steady-state. Tried to chunk uploads client-side but cannot rely on clients being changed immediately. Replacing express.json() with body parsing middleware that streams was tested successfully in a staging app.
Question
What's the safest approach to avoid OOM kills from very large JSON payloads in a Node/Express API, and how do I migrate without disrupting existing clients?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Programming40% match
Node.js Express process exits silently when parsing very large JSON payloads — signs of V8 heap exhaustion
Open0 answers - Databases24% match
PostgreSQL refuses new clients with 'too many connections' after scaling Node workers
Open1 answer - Cloud Computing23% match
Kubernetes pods OOMKilled while node shows 80GB free memory on Ubuntu 20.04 (kubelet+Docker cgroup mismatch suspected)
Open0 answers - Web Development21% match
NGINX returns 504 Gateway Timeout for long-running uploads through a Node backend — how to diagnose?
Open1 answer - Programming21% match
Node.js/Express server CPU spikes and event loop stalls during concurrent multipart image uploads due to synchronous image processing
Open0 answers