Skip to content

Next.js dev server OOM crash — JavaScript heap out of memory (~4GB) on ao start #1935

@i-trytoohard

Description

@i-trytoohard

Bug Report

Reporter: @yyovil
Environment: macOS, Nix-managed Node.js 22.22.1 (nodejs-slim via Nix store), branch feat/droid-agent-plugin

Summary

Running ao start causes the Next.js dev server to consume ~4GB+ of heap memory and crash with a fatal OOM error. The process aborts and the user is forced to kill all running applications to recover system memory.

Crash Details

[next] FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Pre-crash errors observed in terminal:

[direct-terminal] [SessionBroadcaster] fetchSnapshot error: This operation was aborted
[direct-terminal] [MuxServer] Mux connection closed

GC data (last cycles before crash):

Scavenge / Mark-Compact — heap usage ~4087 MB to ~4135 MB

Stack trace highlights:

  • V8 engine heap allocation failures (v8::internal::Heap::AllocateRawWithLightRetrySlowPath)
  • v8::internal::Runtime_AllocateInYoungGeneration
  • Builtins_StringSlowFlatten, Builtins_PromiseFulfillReactionJob
  • libuv event loop (uv__io_poll, uv_run)
  • Final: abort ao start — process exits with code null

Full native stack trace (37 frames):

1: 0x10429c9d4 node::OOMErrorHandler
2: 0x1033d7c40 v8::internal::V8::FatalProcessOutOfMemory
3: 0x103522a30 v8::internal::Heap::AllocateRawWithLightRetrySlowPath
...
11: 0x1033599d4 v8::internal::Runtime_AllocateInYoungGeneration
...
37: 0x1874c3da4 start [/usr/lib/dyld]
[1] 10191 abort ao start

All native frames resolve to /nix/store/0hwvnfndqy5jzdy05hq3rzwvbs9yask2-nodejs-slim-22.22.1/bin/node.

Impact

  • Severity: High — renders ao start unusable on the affected branch/setup
  • User had to quit all running applications to recover from the memory leak
  • SessionBroadcaster fetchSnapshot errors and MuxServer disconnections precede the crash, suggesting a memory leak in the SSE/WebSocket broadcasting layer

Possible Root Causes

  1. SessionBroadcaster snapshot polling — repeated aborted fetch operations may be leaking memory (unaborted fetches accumulating in memory)
  2. MuxServer connection handling — closed mux connections may not be properly cleaned up
  3. Next.js dev server + SSE stream — the 5s-interval SSE stream may accumulate uncollected response objects
  4. Node.js slim buildnodejs-slim from Nix may have different memory management characteristics

Steps to Reproduce

  1. Run ao start on branch feat/droid-agent-plugin
  2. Observe terminal for SessionBroadcaster/MuxServer errors
  3. Monitor memory usage — expect rapid growth to ~4GB
  4. Process aborts with OOM

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions