Skip to content

A simulator capture program killed without its stop leaves SimRenderServer faulting on every frame until shutdown #1888

Done

Description

@V3RON

A simulator capture program that dies without running its stop() leaves its frame callbacks registered in the simulator's SimRenderServer. The renderer then logs one ROCKit Invalid connection UUID specified fault per rendered frame, per dead UUID, until the simulator shuts down. Found while triaging #1583.

Measured on this Mac (Xcode 27.2, iOS 26.4 simulator, macOS 26.6.1, helper built from main c550e87):

helper stopped by stdin close          0 faults on its SimRenderServer
helper SIGKILLed after 30 s            12,605 faults from 1 UUID in 210 s (~60/s, the frame rate)
                                       still ~60/s six minutes later, until simctl shutdown
another simulator up since Nov 19      3 UUIDs, 1 fault each per minute (a still screen renders once a minute)

Two ways Simlock can end the program that way, separate from #1583's viewer-leave order:

  • src/drivers/ios/screen-capture.ts:175-180 stopProgram SIGKILLs after 2 s. The comment at lines 30-32 says the kill keeps "a stuck encoder" from pinning the framebuffer. Measured: a kill pins a registration that does not go away.
  • The helper does not ignore SIGPIPE (vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift:298: only SIGTERM, SIGINT and SIGHUP). A daemon that dies closes stdout and stdin together, and the next frame write kills the program (exit status -13, checked on the host with a closed output pipe) before the stdin thread can start stop(). Options.swift:144 expects EPIPE there instead.

Possible directions: signal(SIGPIPE, SIG_IGN) in ExitSources, so EPIPE reaches the existing viewer-gone path. Also, unregister a dead program's UUIDs from the next program, which needs a check on a simulator.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Defect, for the SIGPIPE half. The test runs a child copy of the test bundle. The child sets up as main.swift and runCapture do, then acts as if its daemon died: stdout and stderr readers gone, stdin at end of file. It writes one frame and one log line. On branch bug/1888-repro:

    vendor/screen-capture/Tests/SimlockCaptureTests/DaemonGoneTests.swift
    testAProgramWhoseDaemonDiedTakesTheViewerGoneWayOutOnItsNextFrameAndLogLine
    
    swift test --package-path vendor/screen-capture --filter DaemonGoneTests
    XCTAssertEqual failed: ("signal 13") is not equal to ("exit 0") - the program died on a write to its daemon's closed pipe, before its stop could run
    

    The SIGKILL half is not reproduced. stopProgram (src/drivers/ios/screen-capture.ts:179-180) kills only a program still running 2 s after its stdin closed, and a healthy program exits before that. Proving the faults stop needs a real simulator: run the fixed helper, kill its daemon, and count ROCKit faults on SimRenderServer.

    Root cause

    vendor/screen-capture/Sources/SimlockCapture/Lifecycle.swift:298: ExitSources ignores SIGTERM, SIGINT and SIGHUP, but not SIGPIPE. So the first write to a closed pipe kills the program, although Options.swift:144 expects it to return EPIPE. A second cause hides behind the first. log() (Options.swift:156) and fail() (:174) use FileHandle.write(_:), which raises an Objective-C exception on EPIPE. The stdin thread calls log("stdin closed") (Lifecycle.swift:310) before onExit, so with only SIGPIPE ignored the program aborts there instead, still before stop().

    Simplest fix

    signal(SIGPIPE, SIG_IGN) at the top of ExitSources.init, and try? FileHandle.standardError.write(contentsOf:) in log and fail.

    SIG_IGN only:   ("exit 1") is not equal to ("exit 0")   (abort, exit 134 outside XCTest)
    both changes:   swift test --package-path vendor/screen-capture -> Executed 19 tests, with 0 failures
    

    Alternatives rejected

    • SIG_IGN alone: the reproduction still fails at log().
    • F_SETNOSIGPIPE on Wire.fd only: stderr writes would still raise SIGPIPE.
    • Dropping the SIGKILL in stopProgram: a stuck program would then never end.

    Risk

    • No CI lane runs swift test. Run it by hand on a Mac with Xcode.
    • Two comments say the program does not ignore SIGPIPE, and both become false with the fix: src/drivers/ios/screen-capture.ts:143-144 and screen-capture.test.ts:49-50. Update them.
    • Not covered: a SIGKILL or a crash still leaves registrations behind. The issue's other direction (the next program unregisters a dead program's UUIDs) needs a simulator check.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: no — clearing a dead program's UUIDs also covers SIGKILL and crashes

    Written by an agent.

  4. removed their assignment
    on Nov 26, 2026
  5. V3RON commented on Nov 26, 2026

    @V3RON
    ContributorAuthor

    Scope (maintainer, 2026-11-26)

    Wide fix, three parts:

    1. The capture program ignores SIGPIPE, and its log() and fail() writes to stderr no longer throw, so a dead daemon leads to stop() (triage report's simplest fix).
    2. A new capture program unregisters the frame callbacks a dead program left in SimRenderServer, so a SIGKILL or crash no longer leaves faults until shutdown. Needs a check on a real simulator.
    3. CI runs swift test --package-path vendor/screen-capture on a macOS runner.

    Done when:

    • The triage reproduction (DaemonGoneTests.swift) passes.
    • After a capture program is SIGKILLed and a new one starts on the same simulator, SimRenderServer logs no ROCKit Invalid connection UUID specified faults for the dead program's UUIDs (slow lane, real iOS simulator).
    • A CI job runs the Swift tests and fails the PR when they fail.
    • The comments at src/drivers/ios/screen-capture.ts:143-144 and screen-capture.test.ts:49-50 match the new SIGPIPE handling.

    Scope set by the maintainer.

    Written by an agent.

  6. added
    bug:ready
    and removed
    bug:new
    on Nov 26, 2026
  7. self-assigned this
    on Nov 26, 2026
  8. 6 remaining items

  9. removed their assignment
    on Nov 26, 2026
  10. V3RON commented on Nov 26, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1888 — R8 (slow-lane fault query not scoped to the leased simulator) open at the review round cap, PR #1893

    Written by an agent.

  11. added
    bug:ready
    and removed
    bug:blocked
    on Nov 27, 2026
  12. self-assigned this
    on Nov 27, 2026
  13. V3RON commented on Nov 27, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1893 at 86e0d1e is ready. R1–R8 are fixed and reviewed. The slow-lane test e2e/slow-ios-stream.test.ts passed 4/4 on a real simulator at this head. The Swift tests and the new swift CI job are green.

    Not done: merge. The gate saw red CI twice on tests outside this diff. First run: Windows src/ports/windows-command.test.ts (conhost killChildren) and Console e2e/console/breakpoints.spec.ts:110; Console is also red on main at 056e298. After gh run rerun --failed: Windows src/agent-device/edge-release.test.ts (retainOnClose). No flaky-test issue exists for any of them.

    Findings: see the Review ledger on the PR.

    Blocked on: the maintainer re-runs the Windows job and merges, or files the flaky tests.

    Written by an agent.

  14. added
    bug:blocked
    and removed
    bug:ready
    on Nov 27, 2026
  15. removed their assignment
    on Nov 27, 2026
  16. added
    bug:ready
    and removed
    bug:blocked
    on Nov 27, 2026
  17. self-assigned this
    on Nov 27, 2026
  18. V3RON commented on Nov 27, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1893 (#1888)
    Parked: none
    Asleep: 41 min

    Written by an agent.

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