Skip to content

Stopping one emulator ends the shared netsimd, which every other emulator's network uses (macOS, Linux) #1690

Closed

Description

@V3RON

On macOS (and likely Linux), stopping one emulator can cut the network of every other emulator on the host.

The emulator starts one netsimd per host, and every emulator's network goes through it. On macOS it starts in the first emulator's process group. Simlock kills an emulator by signalling its whole process group (killProcessTree, process.kill(-pid, …) in src/ports/process-tree-kill.ts), so the kill ends netsimd too.

Seen on macOS 26.6, emulator on Apple silicon, Pixel_8_API_35 started in its own process group:

  PID  PPID  PGID COMM
27540 27537 27540 qemu-system-aarch64-headless
27639 27540 27540 netsimd

kill -TERM -27540 ended both. #1129 fixed the same bug on Windows (killChildren there kills only emulator.exe and its direct children); there, a second emulator lost its network when the first one's tree was killed.

Expected

Stopping one emulator leaves netsimd, and the network of the other emulators, running on every OS.

Part of #1068 (found during its review), affects macOS and Linux.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed. src/ports/process-runner.test.ts, "ends a child spawned with killChildren and leaves the process it started running" (POSIX only), on bug/1690-repro. A child spawned with killChildren: true starts one process, as qemu starts netsimd; a SIGKILL kill ends both.

    pnpm exec vitest run --project unit src/ports/process-runner.test.ts -t "leaves the process it started running"
    
    AssertionError: expected false to be true
     ❯ src/ports/process-runner.test.ts:566:41
        expect(isAlive(sharedPid ?? 0)).toBe(true);
    

    Root cause

    Defect. src/ports/process-tree-kill.ts:115 sends every kill off Windows to the process group (process.kill(-pid, signal)), and windowsKillOf (src/ports/node-process-runner.ts:586) ignores killChildren outside Windows. Off Windows the emulator launcher execs qemu, so the spawned pid is qemu. The issue's ps shows this: qemu leads its own group, and netsimd is its child in that group. The emulator spawns with killChildren (src/drivers/android/emulator.ts:274), but the group kill still reaches netsimd. The symptom appears in every fallback handle.kill("SIGKILL"): a boot that fails (emulator.ts:298), a shutdown that outlives emu kill (emulator.ts:340), and the seed error paths in seeds.ts. A normal emu kill exit sends no signal (isRunning guard).

    Simplest fix

    Off Windows, a killChildren child is signalled alone. windowsKillOf returns "children" on every OS, killProcessTree sends process.kill(pid) for "children" instead of -pid, and the code: null override in both handles applies on Windows only. Then rewrite the comments in process-runner-types.ts:31-39, emulator.ts:272 and the test's why: at process-runner.test.ts:516.

    3 lines in node-process-runner.ts, 1 in process-tree-kill.ts
    pnpm exec vitest run --project unit src/ports/process-runner.test.ts src/ports/windows-command.test.ts src/drivers/android
    Test Files  43 passed (43)   Tests  785 passed | 6 skipped (791)
    

    Alternatives rejected

    • Kill the group but spare a process named netsimd: brittle, because it matches on a binary name.
    • Kill the child and its direct children, as on Windows: off Windows netsimd is qemu's direct child.

    Risk

    • On Linux this relies on the launcher exec'ing qemu. Checked on macOS only (the launcher imports _execv, and the issue's ps agrees). If a launcher spawns qemu instead, qemu outlives the kill.
    • Any other child that qemu starts in its group now outlives a fallback kill. crashpad_handler calls setsid, so the group kill never reached it anyway.

    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.

  4. removed their assignment
    on Nov 18, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 18, 2026
  6. self-assigned this
    on Nov 18, 2026
  7. V3RON commented on Nov 18, 2026

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1694 (head 3a63435). Off Windows, a killChildren process is now signalled alone, not its whole process group, so killing one emulator's qemu no longer takes netsimd with it. A fast-lane test in src/ports/process-runner.test.ts proves it with a stand-in child. Review round 1 found one stale test comment (fixed); the fix-check passed. PR is ready.

    Not done: the check on real emulators. No slow-lane test starts two emulators, stops one and checks netsimd, so the hardware stage could not run. The gate was not run.

    Findings: none open. One review note posted on the PR.

    Blocked on: a person verifying on macOS or Linux with two real emulators (stop one; netsimd and the other's network stay up), or a slow-lane case for it. Then remove needs-hardware and run the gate (merge-pr.sh 1694) or merge by hand.

    Written by an agent.

  8. added
    bug:blocked
    and removed
    bug:ready
    on Nov 18, 2026
  9. removed their assignment
    on Nov 18, 2026
  10. V3RON commented on Nov 18, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1690 — PR #1694 needs-hardware: no slow-lane test runs two real emulators to check netsimd survives
    Waiting: none
    Decided: none

    Written by an agent.

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

    @V3RON
    ContributorAuthor

    Handoff

    Done: PR #1694 (head 8c6dc4e) is ready, CI is green and the review is complete with no open findings. A new slow-lane case in e2e/slow-android-smoke.test.ts leases two emulators. It freezes the qemu that owns netsimd's process group, so releasing it reaches the SIGKILL fallback, then checks that netsimd and the other emulator's network survive. It passes on this Mac. With the fix reverted it fails, because netsimd dies. needs-hardware is removed.

    Not done: the merge. The gate held the PR under the fast track because it has a "Decision taken" comment: a slow-lane case was added instead of parking on review finding R2.

    Findings: none open (R1 and R2 fixed).

    Blocked on: fast-track: PR #1694 has a "Decision taken" comment. The maintainer merges the PR, or removes fast-track from #1690 and runs merge-pr.sh 1694.

    Written by an agent.

  14. V3RON commented on Nov 18, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: none
    Parked: #1690 — PR #1694 held by the fast track (Decision taken comment); hardware verified
    Waiting: none
    Decided: #1690 — how to prove the fix on real emulators → a slow-lane case that reaches the SIGKILL fallback (fails without the fix)

    Written by an agent.

  15. removed
    bug:ready
    on Nov 18, 2026
  16. removed their assignment
    on Nov 18, 2026
  17. added
    bug:blocked
    and removed
    fast-track
    on Nov 18, 2026
  18. removed
    bug:blocked
    on Nov 18, 2026
  19. added a commit that references this issue on Nov 19, 2026
    6551fc0
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

    platform:android

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions