Skip to content

Worker daemon aborts on a V8 out-of-memory error after hours of agent-device e2e traffic, ending every lease #1409

Closed

Description

@vitalyiegorov

Summary

The worker daemon (dist/daemon/main.js, supervised by com.callstack.simlock.worker) aborted twice on a V8 out-of-memory error, even with NODE_OPTIONS=--max-old-space-size=12288. Each restart ended every lease on the worker at once (#1103), so every e2e test running through the gateway failed together. The callers saw the worker holding this device is not connected to the gateway, followed by Daemon RPC request failed and HTTP 500s while the worker was coming back.

Environment

  • Worker: Mac Studio, Apple silicon, 14 cores, 36 GiB RAM, macOS 15.7.4, Xcode 26.3 (17C519), Node 22.23.4 (Homebrew node@22).
  • simlock: upstream main at 0aa6a58 plus fix(agent-device): an allocate's device mode reaches the lease request (#1223) #1225 cherry-picked (package version 0.5.0). One gateway on the same host, reached through a Cloudflare tunnel.
  • agent-device 0.21.36 with the agent-device capability enabled. Most leases came through /v1/agent-device/rpc: tester-army e2e suites that take screenshots and record video on every test.
  • Capacity at the time: fixed, iOS 11 running / 11 devices, Android 2 / 2, warm pool 8 slim iPhone 17 Pro.

The two crashes

Process launched Crashed Uptime
2026-11-03 07:03:25 +01:00 2026-11-03 14:42:55 +01:00 7.6 h
2026-11-04 15:38:52 +01:00 2026-11-05 22:11:47 +01:00 30.5 h

Both are EXC_CRASH (SIGABRT), abort() called from node::OOMErrorHandler, in the launchd worker process (parent pid 1).

Crash on Nov 3, while JSON.parse allocated a string:

node::OOMErrorHandler
v8::internal::V8::FatalProcessOutOfMemory
v8::internal::Heap::FatalProcessOutOfMemory
v8::internal::Heap::CollectGarbage
v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath
v8::internal::FactoryBase<Factory>::NewRawStringWithMap<SeqOneByteString>
v8::internal::JsonParser<unsigned char>::MakeString
v8::internal::JsonParser<unsigned char>::Parse
v8::internal::Builtin_JsonParse

Crash on Nov 5, under external memory pressure while a typed array's buffer was being set up:

node::OOMErrorHandler
v8::internal::V8::FatalProcessOutOfMemory
v8::internal::Heap::FatalProcessOutOfMemory
v8::internal::Heap::CollectGarbage
v8::internal::Heap::ReportExternalMemoryPressure
v8::Isolate::AdjustAmountOfExternalAllocatedMemory
v8::internal::JSArrayBuffer::Setup
v8::internal::JSTypedArray::GetBuffer
v8::internal::Builtin_TypedArrayPrototypeBuffer

The JavaScript frames are not symbolicated in the .ips files. The worker log had rotated by the time we looked, so there is no log context from the minutes before either crash.

What we saw on the host

At 31 h after the second restart, with the farm at full load:

  • The worker's RSS was 1.75 GiB, and the agent-device simulator daemon it spawns was at 1.9 GiB. RSS swung by about 1 GiB between samples 20 s apart, so the host was swapping them.
  • Swap was 9.4 GiB, more than its 8 GiB starting size, macOS pressure was warn, and vm_stat counted 35 M pageouts. The booted simulators took far more RAM than the host has.
  • simlock status --json listed 351 devices in state deleted (247 iOS, 104 Android), next to 13 live ones. The worker keeps every deleted device in memory and in the status reply.
  • ~/.simlock/history.db was 480 MB, and ~/.simlock/agent-device/sessions held 12,556 session folders (4.9 GiB). They are never pruned.

The memory starvation clearly made things worse. Still, an Apple-silicon worker should not run out of a 12 GiB V8 heap: its live state is about 13 devices and a few leases. Something keeps growing over the daemon's lifetime, or one reply is buffered whole. Both stacks fit the second case: a large JSON body parsed into one string, and a large ArrayBuffer, such as a relayed screenshot, recording or exec output.

Questions / suggestions

  1. Does the worker or the relay buffer a whole response body (agent-device RPC replies, screenshots, recordings, device.exec output, lease files) before forwarding it? If so, could it stream instead and cap the size?
  2. Does anything keep growing for the life of the process: per-lease or per-request maps, device rows in state deleted, the event buffer, history writes or relay connections?
  3. A --heapsnapshot-near-heap-limit (or node --heap-prof) recipe in the worker docs would let operators capture the next one. We have added nothing like that yet.
  4. Together with agent-device: a worker restart ends every lease whose device is still running #1103, a worker restart is a farm-wide outage for the agent-device front. Re-attaching running devices to their leases after a restart would turn an OOM into a blip.

Mitigation on our side

We now run upstream main 0ebd818 with the memory-pressure admission work (#1398–#1403), and we cut capacity to iOS 7 / Android 2 (9 total) with iosSlimBytesPerDevice at 3 GiB. Swap dropped to 1.1 GiB and pressure is normal. We will add RSS samples here if the worker keeps growing on this build.

Activity

  1. added
    bug:new
    on Nov 7, 2026
  2. self-assigned this
    on Nov 7, 2026
  3. V3RON commented on Nov 7, 2026

    @V3RON
    Contributor

    Not reproduced on main. Both crashes ran a build without the fix for #1242, and nothing else found on the worker matches the stacks.

    What the crashes match

    $ git merge-base --is-ancestor e7648763b 0aa6a58  → no
    $ git merge-base --is-ancestor e7648763b 0ebd818  → yes
    

    Paths checked on the worker (question 1)

    • Agent-device replies, screenshots, recordings and artifact downloads stream. The front caps an RPC request at 1 MiB (src/agent-device/shared/rpc.ts:3) and a download at 2 GB without buffering it (src/agent-device/host/host.ts:52). @agent-device/proxy 0.21.35 passes upstreamResponse.body through.
    • Relay bodies stream in both directions (src/daemon/relay.ts:413).
    • Only allocate and release replies are read whole (src/agent-device/host/lease-end.ts:32, :59). Both are small.

    Things that keep growing (question 2)

    Neither explains a 12 GiB heap. Each is filed on its own:

    history.db is capped at eventLog.maxBytes (256 MiB of events by default, src/core/config.ts:1021), plus metrics.

    What would let me reproduce it on 0ebd818

    1. Whether the e2e suites still send large exec stdin, and whether any exec now fails with BAD_REQUEST.
    2. A worker crash, if one happens, with NODE_OPTIONS="--max-old-space-size=12288 --heapsnapshot-near-heap-limit=1 --diagnostic-dir=<dir>" set in the service, and the .heapsnapshot it writes.
    3. Without a crash: the worker's RSS every hour over a day of load, and simlock status --json | wc -c at the start and the end.

    Written by an agent.

  4. added
    bug:needs-info
    and removed
    bug:new
    on Nov 7, 2026
  5. removed their assignment
    on Nov 7, 2026
  6. vitalyiegorov commented on Nov 9, 2026

    @vitalyiegorov
    ContributorAuthor

    Data point (no OOM this time), simlock 0.6.0 worker on macOS 15.7.4, 36 GiB, capacity iOS 10 / Android 3:

    • Worker RSS climbs steadily: 9.4 GiB at 22h41m uptime (2026-11-08, restarted), then 8.36 GiB at 1d10h33m (2026-11-09). The normal working range is 0.3–2.1 GiB under a 12 GiB heap.
    • No new node-*.ips since 2026-11-05. Pressure normal, no daemon.log errors.
    • status --json keeps hundreds of state: deleted device records (about 830 at the last count). They are our main suspect for the retained memory.
    • Restarted again after draining: RSS 0.18 GiB. Without restarts, we expect it to reach the 12 GiB heap in about 1.5–2 days.
  7. added
    bug:new
    and removed
    bug:needs-info
    on Nov 9, 2026
  8. vitalyiegorov commented on Nov 11, 2026

    @vitalyiegorov
    ContributorAuthor

    Another data point for the slow worker RSS growth (no OOM this time). Host: macstudio (macOS 15.7.4 arm64, simlock 0.6.0, Node 22.23.4), a 10 iOS / 3 Android worker.

    Restart Uptime Worker RSS
    2026-11-08 22h41m 9.4 GiB
    2026-11-09 1d10h33m 8.36 GiB
    2026-11-11 1d06h18m 6.70 GiB

    After each restart RSS goes back to about 0.15 GiB. The normal working range is 0.3–2.1 GiB, so the growth looks like a leak and not load. This time there were 0 leases, no new node-*.ips (the last one is from 2026-11-05), memory pressure was normal and swap was 1.1 GiB. I drained the worker, restarted it with launchctl kickstart -k, then undrained it.

  9. self-assigned this
    on Nov 11, 2026
  10. V3RON commented on Nov 11, 2026

    @V3RON
    Contributor

    Reproduction

    Reproduced on main 84c85b11, which corrects the earlier note. The worker keeps about 17 KiB of heap for every call the gateway relays to it, so the growth follows agent-device traffic, not leases. Test on bug/1409-repro: src/daemon/relay.test.ts, "lets every Request it handed a target be collected once the relay has answered, a GET with no body and a PUT with one".

    $ pnpm exec vitest run --project unit src/daemon/relay.test.ts
    AssertionError: expected [ false, false ] to deeply equal [ true, true ]
     ❯ src/daemon/relay.test.ts:249:60
    

    A scratch probe (gateway and worker in one process, fake agent-device, heap after a full GC):

                               200 calls   800 calls
    agent_device.command       +4.0 MB     +13.5 MB
    GET /artifacts (256 KiB)   +1.6 MB     +10.9 MB
    kept after 800 commands: 800 Channel, 800 Request, 800 Response, 2400 Headers
    6.7 GiB / 17 KiB ≈ 410k relayed calls ≈ 3.8 per second over 30 h
    

    Root cause

    Defect. src/daemon/relay.ts:297 stores the target's Request in active.request, and the finally at :157 never clears it. The Request carries signal: active.controller.signal (:336), so Node's fetch registers the Request's own AbortController in its requestFinalizer with that signal as the held value. The abort listener at :153 closes over active, so the held value reaches the registry's own target, which is therefore never collected. Every relay keeps its Request, LinkChannel, headers and streams for the life of the process.

    requestFinalizer → held value {signal} → active.controller.signal
      → abort listener (relay.ts:153) → closure {active, channel}
      → active.request → Request → its AbortController (the registry's target)
    

    Simplest fix

    Add active.request = undefined; to #admitted's finally in src/daemon/relay.ts:157, after this.#active.delete(input.relayId);.

    src/daemon/relay.test.ts                                                    7 passed (3 runs)
    relay-worker.e2e, relay-gateway.e2e, gateway-front, edge-downloads (unit)   153 passed
    relay-promises.timing.test.ts (timing)                                      8 passed
    probe: agent_device.command +1.7 MB at 800 calls, flat from 400
    

    Alternatives rejected

    • Remove the :153 listener at the end: any other closure over active on that signal rebuilds the cycle.
    • Stop keeping the Request: :56 needs it alive while a target holds only its signal.
    • Build the Request without our signal: changes every target's abort path.

    Risk

    • Nothing reads active.request after #admitted returns; a two-way relay's pipe ends before it does.
    • The test forces GC through setFlagsFromString("--expose-gc"), new in this repo.
    • After the fix, 800 calls still leave 800 AbortSignal and Timeout pairs. They look like pending timeouts that free themselves when they fire; not proven.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  11. removed their assignment
    on Nov 11, 2026
  12. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 11, 2026
  13. self-assigned this
    on Nov 11, 2026
  14. V3RON commented on Nov 11, 2026

    @V3RON
    Contributor

    Handoff

    Done: PR #1533 clears active.request in the relay's finally (src/daemon/relay.ts), with the triage test. Audit probed 1/1. Review round 1 passed (0 blocking, 1 note), the ledger is posted, the PR is ready, and the fast-track exit check passes.

    Not done: merge.

    Findings: CI failed twice, on runs 43053157583 (Console, Console 1/2 and 2/2) and 43053158033 (Real proxy), both in Playwright's browser install step: Temporary failure resolving 'azure.archive.ubuntu.com', apt exit 100. That is the runner's network, before any test runs. No test failed.

    Blocked on: GitHub runner DNS. Once the Ubuntu mirror resolves, rerun with gh run rerun <id> --failed and run .agents/scripts/merge-pr.sh 1533, or re-run deliver 1409.

    Written by an agent.

  15. added
    bug:blocked
    and removed
    bug:ready
    on Nov 11, 2026
  16. removed their assignment
    on Nov 11, 2026
  17. V3RON commented on Nov 11, 2026

    @V3RON
    Contributor

    Delivery run

    Merged: none
    Parked: #1409 — CI red twice in Playwright's browser install (runner DNS could not resolve the Ubuntu mirror); PR #1533 passed review and is ready
    Waiting: none
    Decided: none
    Asleep: 20 min

    Written by an agent.

  18. added a commit that references this issue on Nov 17, 2026
    5ccccba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:blockedfast-track

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions