FULL AI ANALYSIS

Express API worker OOMKilled when receiving very large JSON body — body-parser buffers whole payload

Generated Oct 16, 2026, 9:43:08 AM

Analysis summary

The immediate cause is buffering the entire JSON body in memory (express.json/body-parser), which, combined with container cgroup limits and V8 heap limits, triggers kernel OOM. This is an application design issue (synchronous full-buffer parsing) rather than a Node.js bug. Increasing memory is a stopgap; robust solutions use streaming parsing, size limits, or offloading large payloads to object storage.

Possible causes

Use of body-parser (express.json()) which buffers entire JSON payload into memory, causing V8 heap exhaustion and kernel OOM in constrained containers.

90%

Container memory limits too low for peak payloads and Node not configured with sufficient --max-old-space-size causing OOM.

70%

Memory leak or retained references in application code that magnify memory usage with large payloads (less likely given reproducer behavior).

25%

Suggested fixes

1

Diagnostic step 1

Enforce a maximum request size at the ingress or reverse proxy (e.g., nginx client_max_body_size or API gateway limits) to reject overly large requests gracefully. This is reversible and low-risk.

2

Diagnostic step 2

Replace body-parser usage for large endpoints with a streaming JSON parser (e.g., JSONStream, stream-json) that processes the request body chunk-by-chunk and avoids buffering the entire payload in memory.

3

Diagnostic step 3

Implement an upload-to-storage pattern: require clients to upload large JSON blobs to object storage (presigned URL), then send a small reference to the API to process asynchronously. This avoids large synchronous processing and is safer for reliability.

4

Diagnostic step 4

Add application-level request size limits in Express (limit option) and return a 413 error for too-large payloads while you roll out streaming or staged uploads.

5

Diagnostic step 5

Enable diagnostic logging for GC and heap usage (node --trace-gc, heapdump on OOM) and add resource alerts; if OOM persists after changes, collect heapdumps and escalate to SRE with heap profiles for deeper analysis.