Skip to content

iOS Simulator screen stream: ROCKit invalid-connection fault storm and multi-second stalls #1583

Done

Description

@0xdaniell

Environment

  • Measured: Simlock 0.7.0, packaged iOS screen-capture driver and helper; iOS Simulator runtime 26.5, running in a macOS VM. Measurements on 2026-11-15. macOS and Xcode versions and host hardware are not established here.
  • Measured: The fault storm was seen on every streamed simulator examined, including simulators held by other leases, between 19:56 and 20:16 local time. This does not establish behavior on every installation.

Symptoms and evidence

Measured: Opening a stream was followed by two simlock-screen-capture process starts, PID 4985 at 20:24:43 and PID 5151 at 20:24:52 local time. This establishes two starts, not that their lifetimes overlapped or why the second was started. From about 20:24:49, the streamed device's SimRenderServer (PID 3502) emitted approximately 120–270 faults per second. Each was followed by an Activity for state dumps entry (subsystem ROCKit, category RuntimeIssues, sender ROCKit.framework). The fault text included:

ROCKit Soft Assertion Failure ... Failed Condition: errorPropagated -- Runtime error encountered without error propagation channel, aborting. Error: NSPOSIXErrorDomain Code=22 (Invalid connection UUID specified.) connectionUUID=...

Measured: One connection UUID accounted for about 17,600 faults in three minutes; 15 others accounted for 605 each. The message's word “aborting” does not by itself establish that the server process exited.

Measured: Over a 180-second run, the app reported 7,441 unique and 3,232 lost frames, about 59.3 frames/s combined. The received stream nonetheless had gaps of roughly 2–9 seconds. After gaps, chunks resumed at about 16 ms spacing, beginning with a large delta frame and no backlog burst. Per-second guest logs show SimRenderServer and the device's processes silent during each observed stall, followed by a catch-up burst of 500–1,300 lines; ControlCenter and airportd continued logging.

Hypothesis: The gap pattern points toward interruption before or during guest-side capture/delivery rather than ordinary transport buffering. Log silence is consistent with a blocked SimRenderServer, but does not by itself prove where it blocked or exclude every downstream cause. The app's aggregate frame count does not establish uninterrupted frame production at every instant.

Reproduction to try

  1. On a Mac with Simlock 0.7.0 and an iOS 26.5 simulator, start the worker and lease a simulator using the documented workflow, for example simlock lease --platform ios --device "iPhone 16". Launch an app with continuous visible animation or a frame counter.

  2. Open one Simlock screen stream using the usual viewer. Keep it open for at least three minutes. Record received frame or chunk timestamps and sizes, and the app's frame count. Observe helper starts and exits, for example with ps sampling, including command arguments and parent PIDs.

  3. In another terminal, capture the relevant unified logs while the stream is open, for example:

    log stream --style compact --info --debug --predicate 'process == "SimRenderServer" OR process == "simlock-screen-capture"'

    Count Invalid connection UUID specified faults by second and UUID, and correlate stream gaps with SimRenderServer and other process logs. Compare an equivalent interval without a stream, then close and reopen the viewer and check whether the faults persist. Redact identifiers before sharing logs.

Expected: A continuous stream, clean helper lifecycle, and no sustained invalid-connection fault storm. Observed: The rates and stalls above. Unverified: This exact procedure has not been rerun as a minimal independent reproduction; the trigger for the second helper and whether a single open suffices are unknown.

Mechanism to investigate

  • Code-backed: <simlock>/dist/drivers/ios/screen-capture.js:37–48, 53–79 starts a helper for each successful capture open. The driver checks the abort signal before starting, but does not subscribe to it after starting. The returned close operation is idempotent.
  • Code-backed: <simlock>/dist/stream/worker-link.js:11–22, 32–40 registers a slot and starts a feed for each serve call, and releases on abort or close. <simlock>/dist/stream/captures.js:23–36, 50–66 keeps a set of slots per device; it does not enforce one capture per device. Multiple opens can therefore spawn multiple helpers, and a new open need not wait for another slot's close. These files alone do not show an automatic restart or prove concurrent helpers in this incident.
  • Code-backed: <simlock>/dist/drivers/ios/screen-capture.js:90–109, 123–128 closes on stream cancellation, read error, or completion; stopping closes stdin, waits up to two seconds, then sends SIGKILL and waits up to two more seconds. This JavaScript does not call a display detach API. Whether the native helper detaches on stdin EOF or before a forced kill is not established by the JS. <simlock>/dist/stream/feed.js:4–8, 35–38, 80–87 has a 30-second default silence bound and closes on read failure; the reported 2–9-second gaps alone do not reach that default.
  • Binary inspection: Strings in the packaged helper reference SimulatorKit.framework and framebuffer/display descriptors. Strings do not establish the connection lifecycle, an actual ROCKit API call, or a detach implementation.
  • Hypothesis: A capture client exits or is replaced without fully tearing down a display/ROCKit connection. SimRenderServer may then repeatedly service a stale connection UUID and fault, possibly on frame-related work, with periodic blocking and stream stalls. The fault storm starts before the second observed helper start, so that second start cannot explain the onset in this timeline. A pre-existing stale connection, an earlier lifecycle event, or a different Apple/runtime defect could also explain it.

Suggested investigation and fixes

  1. Trace each stream request, helper PID, exit reason, native connection UUID and detach completion; correlate those with fault onset and stalls. Determine whether starts are retries, separate viewers or another path.
  2. Consider a single shared capture per device/stream with reference-counted viewers, or serialize replacement so the previous helper has exited and detached before the next attaches. Preserve intended multi-viewer behavior.
  3. In the native helper, explicitly unregister and detach the display/framebuffer connection on normal EOF, cancellation and handled errors before exiting. Ensure close waits for teardown; investigate how to recover when forced termination prevents cleanup.
  4. Investigate whether the relevant SimulatorKit/ROCKit interface supports an error-propagation handler, and install and handle one where supported. Avoid assuming the assertion can be fixed solely in Simlock.
  5. Add lifecycle coverage for rapid open/close, overlapping requests, failed startup and forced termination, plus an integration check that faults cease and frames continue after reconnect. Compare the same scenario without Simlock to isolate a Simulator defect.

Explicitly unverified

  • The exact macOS, Xcode and hardware versions; whether physical Macs or other simulator runtimes reproduce this.
  • Whether the two helpers overlapped, which requests caused them, whether either was killed, or whether a restart happened.
  • Which client owns any faulting UUID, whether it is stale, and whether native teardown or an error handler is absent.
  • Whether the fault storm causes the stalls, the precise blocking location, or whether a transport or encoder issue contributes.
  • Whether the storm occurs without a Simlock stream, persists after closing it, or is specific to Simlock rather than an Apple framework issue.
  • Whether the proposed changes eliminate faults or stalls; none has been tested.

Addendum (same day): trigger and a logging A/B

  • Measured: Our test harness opens a short probe stream through the gateway (about 6 s, ~7 MB) and closes it immediately before the real stream. That fits the two helper starts per run. A viewer that opens and closes a stream quickly (a reconnect, a preview) may leave the same state; the storm was also present on simulators our harness never touched.
  • Measured (A/B, 4 x 300 s, ABBA): turning ROCKit logging off in the guest (log config --subsystem ROCKit --mode level:off) did not consistently reduce stalls (pairs: 23 -> 7 and 7 -> 8 stalls >= 0.3 s). So the cost is not the logging itself. Across arms, stalls were higher when the storm ran for the whole arm (326 s of SimRenderServer log activity: 12 unexplained stalls) than when it was intermittent (110 s: 2). This is a correlation only.
  • Likely quickest trigger (from our runs, not yet reduced further): open the gateway's stream for a lease (GET /v1/leases/<lease>/stream), read for about 6 s, close it, then open it again and keep it open. Then watch SimRenderServer's log for Invalid connection UUID specified.

Activity

  1. V3RON commented on Nov 18, 2026

    @V3RON
    Contributor

    @0xdaniell could you retest this on Simlock 0.8.0? Since 0.7.0, all viewers of one device on a worker share a single capture (#602, PR #1614), so a second open no longer starts a second simlock-screen-capture helper. Each capture also sends a key frame every 5 s (ADR 0079). If the invalid-connection fault storm or the 2–9 s stalls still show up with one helper running, please post the same counts (faults per second, helper PIDs, gap lengths) and we'll triage from there.

    Written by an agent.

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

    @V3RON
    Contributor

    Handoff

    Done: read the stream link and native helper on main (c550e87). No repro branch: only a real simulator shows the storm.

    Not done: a failing test, root cause, report.

    Findings:

    • The mechanism exists, narrowed. Concurrent viewers share one helper, but a reopen right after the last viewer left starts a new helper while the old one is still stopping. create.test.ts ends5 pins this on purpose; it passes.
    • Overlap is a weak cause. The helper unregisters its callback UUIDs on stdin EOF. The storm started at the probe's close (~20:24:49), before the second start (20:24:52).
    • Sharing (feat(stream): viewers of one device on a worker share one capture #1614) first ships in 0.8.0, not 0.7.0.
    src/stream/worker-link.ts:121-126   stopped broadcast -> start(device) at once, no wait for slot.release()
    src/drivers/ios/screen-capture.ts:175-180   closeStdin, 2 s, SIGKILL, 2 s
    vendor/screen-capture/.../FrameCapture.swift:316-327   stop() unregisters callback UUIDs (skipped on SIGKILL)
    

    Blocked on: maintainer approval to run on one real iOS 26.5 simulator, three 3-min arms. Count faults, helper PIDs, gaps:

    A  open lease stream 6 s, close, reopen at once, hold 180 s   (today's overlap)
    B  same, reopen after the old helper PID is gone               (serialized)
    C  no stream 180 s; then the helper alone, stopped by stdin EOF vs SIGKILL
    log stream --style compact --predicate 'process == "SimRenderServer" OR process == "simlock-screen-capture"'
    

    A storm in A only means serialize in worker-link.ts. A storm after a clean EOF in C means the helper. None means #1551's fixes covered it.

    Written by an agent.

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

    @V3RON
    Contributor

    Reproduction

    The storm comes from a capture program that dies before its stop(). When the last viewer leaves, Simlock lets go of the program's stdout before it closes stdin. The program does not ignore SIGPIPE, so its next frame write kills it.

    src/drivers/ios/screen-capture.test.ts, "cancelling the body stops the program through stdin before letting go of its stdout, and a second close does not stop it again", on bug/1583-repro:

    pnpm exec vitest run --project unit src/drivers/ios/screen-capture.test.ts
    AssertionError: expected [ false ] to not include false   (stdout cancelled while stdin still open)
    

    Approved arms, one iOS 26.4 simulator (26.5 is not installed), Xcode 27.2, the helper driven as stopProgram drives it:

    arm                               faults on its SimRenderServer
    C  no stream, 180 s               0
    C  helper, stdin close            0
    B  6 s, stop, wait for exit, 180 s  0
    A  6 s, stop, reopen at once, 180 s 0   (overlap 32 ms)
    C  helper, SIGKILL                12,605 from 1 UUID in 210 s, ~60/s; still ~60/s 6 min later
    helper with no reader on its output pipe: exit status -13 (SIGPIPE)
    

    Stalls are not explained: A and B had 28–29 gaps of 0.3 s or more (longest 6.1 s) with zero faults, on a host also running another slow-lane test.

    Root cause

    Defect. src/drivers/ios/screen-capture.ts:142-145 cancels the stdout reader, which destroys the pipe, and only then calls close(), which closes stdin. Every viewer-leave stop reaches it first through src/stream/broadcast.ts:61. The next frame write raises SIGPIPE (Lifecycle.swift:298 ignores only SIGTERM, SIGINT and SIGHUP). The program then dies without FrameCapture.stop() (FrameCapture.swift:316-327), which unregisters its callback UUIDs. SimRenderServer then faults on every frame for each dead UUID, until the simulator shuts down. The overlapping reopen is not the cause.

    Simplest fix

    Swap the two lines: await close() first, then reader.cancel. With that swap the reproduction passes, and so do 113 tests across the driver's screen tests and src/stream/.

         cancel: async (reason) => {
    -      await reader.cancel(reason).catch(() => undefined);
           await close();
    +      await reader.cancel(reason).catch(() => undefined);
         },

    Alternatives rejected

    Risk

    • While close() waits, nobody reads stdout. A full pipe blocks the helper's write, but its stdin thread still runs stop() within the 2 s grace.
    • Not run on a simulator through the daemon; a slow-lane check: close a lease stream and expect zero faults.

    Fast track

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

    Side findings

    Written by an agent.

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

    @V3RON
    Contributor

    Delivery run

    Merged: #1890 (#1583)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  14. added a commit that references this issue on Nov 26, 2026
    1cc9252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions