Skip to content

Worker aborts with V8 OOM in JSON.parse when several exec requests carry large stdin payloads; all leases lost #1242

Closed

Description

@vitalyiegorov

Summary

A simlock 0.5.0 worker (Node 22.23.4, macOS, gateway mode) aborts with a V8 out-of-memory error while parsing an incoming message with JSON.parse. This happens when several POST /v1/leases/<id>/exec requests carrying a large stdin (base64 payloads of tens of MB) are in flight at once. Every lease on that worker is lost: in-flight execs return 503 after about 105 s, and later calls get 404 UNKNOWN_LEASE.

Evidence

Crash report node-2026-11-03-144256.ips:

EXC_CRASH (SIGABRT) — abort() called
node::OOMErrorHandler
v8::internal::V8::FatalProcessOutOfMemory
v8::internal::Heap::CollectGarbage
v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath
v8::internal::FactoryBase::NewRawStringWithMap<SeqOneByteString>
v8::internal::JsonParser<unsigned char>::MakeString
v8::internal::JsonParser<unsigned char>::Parse
v8::internal::Builtin_JsonParse
  • Worker log: the next start at 13:42:56Z logs Recovered stale daemon socket / Daemon started and re-establishes the gateway uplink. launchctl reports the last exit as -6.
  • Gateway log for one lease: device.exec → POST …/exec 503 after 105,242 ms → the client releases → POST …/exec 404 UNKNOWN_LEASE.
  • Workload: a tester-army e2e suite with 10 workers. Each worker uploads an ~89 MB fixture archive (deflated, base64 in stdin) through exec (simctl spawn <helper> untar) at the same moment. The host's load average was about 70.
  • The same burst also produced Cloudflare 524s and connection resets on other runs, because each exec holds a single long request.

Root cause

The worker (or its gateway uplink) materialises each exec request, stdin included, as one JSON string and parses it on the heap. Concurrent large stdin payloads exceed the V8 heap limit, and the process aborts instead of rejecting the request.

Suggested fix

  1. Bound the accepted exec stdin size per request, and the total in flight per worker. Reject an over-limit request with a typed error (413/PAYLOAD_TOO_LARGE) instead of crashing.
  2. Stream stdin through the uplink and into the child process instead of parsing it as a single JSON string, or offer a separate upload endpoint, so large file transfers don't sit on the JSON path.
  3. Optionally, keep lease state across a worker restart (the leases were lost even though the devices survived).

On the client side, we are capping concurrent large uploads (consumer issue linked below), but a worker should not be crashable by request size.

Activity

  1. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Another suite hitting the same limits: budgie's e2e port (budgie-at/budgie#1867) sends fixtures as base64 raw-deflate on exec stdin (a tar of the app's Documents/, via a helper simulator app), and limits app uploads to 3 at a time because 10 parallel uploads through the Cloudflare tunnel ended in 524 errors.

    Written by an agent.

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

    @V3RON
    Contributor

    Written by an agent.

  5. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Reproduction

    Gap: nothing bounds device.exec's stdin. The 8 MiB limit and BAD_REQUEST in the test are a proposal.

    src/gateway/dispatcher.test.ts, "refuses a device.exec whose stdin is longer than 8,388,608 characters with BAD_REQUEST and forwards nothing to the worker, and forwards one at 8,388,608" (branch bug/1242-repro).

    pnpm exec vitest run --project unit src/gateway/dispatcher.test.ts -t "longer than 8,388,608"
    
    AssertionError: promise resolved "{ exitCode: +0 }" instead of rejecting
     ❯ src/gateway/dispatcher.test.ts:2532:48
         await expect(exec("A".repeat(8_388_609))).rejects.toMatchObject({ code: "BAD_REQUEST" });
    

    Root cause

    src/contract/operations.ts:471 declares stdin: z.string().optional() with no bound, which breaks safety rule 10 ("never store one unbounded"). The gateway forwards any size (src/gateway/fleet-coordinator.ts:602) as a single uplink text message. The worker's socket client takes up to 100 MiB per message (the ws default, src/ports/uplink-websocket.ts:295). DaemonServer then buffers the line with no cap (src/daemon/server.ts:778) and JSON.parses it (:816), the frame in the crash stack. The string lives until the command exits; ten ~100 MB uploads fill the ~4 GB heap. The reporter's point 3 needs a correction: leases are rows in state.db and survive a restart. In the gateway log, the 404 UNKNOWN_LEASE comes after the client's own release.

    Simplest fix

    stdin: z.string().max(8_388_608).optional() in the contract. No protocol bump (maintainer, 2026-11-05): the wire shape stays a string, so the fix commit carries the trailer "Protocol-bump: none (stdin size cap; wire shape unchanged)" for protocol-bump-check.mjs. The gateway's and the worker's runDispatch then refuse an oversized stdin before forwarding or spawning. Large file transfer (stream stdin, or device.upload from ADR 0005 §19b′) is a feature: it needs a spec session.

    Alternatives rejected

    • New PAYLOAD_TOO_LARGE/413 code: BAD_REQUEST already refuses bounds, like requesterId's 256.
    • Limit execs in flight per worker: more state, and not needed once each request is bounded.

    Risk

    • Breaking for anyone uploading more than 8 MiB today, including the tester-army and budgie suites. Release notes needed.
    • The HTTP route still reads and parses the whole body before the refusal (src/http/lease-declarations.ts:138). A body limit on that route would avoid it.
    • DaemonServer#read still has no line cap for local socket clients.

    Written by an agent.

  6. removed their assignment
    on Nov 5, 2026
  7. added
    bug:ready
    and removed
    bug:new
    on Nov 5, 2026
  8. self-assigned this
    on Nov 5, 2026
  9. V3RON commented on Nov 5, 2026

    @V3RON
    Contributor

    Delivery run

    Merged: #1318 (#1242)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

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

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions