Skip to content

Fix EmulatorRunner early exit detection and macOS fork handling#313

Closed
rmarinho wants to merge 1 commit intofeature/emulator-runnerfrom
dev/emulator-early-exit
Closed

Fix EmulatorRunner early exit detection and macOS fork handling#313
rmarinho wants to merge 1 commit intofeature/emulator-runnerfrom
dev/emulator-early-exit

Conversation

@rmarinho
Copy link
Member

Summary

Adds early process exit detection to EmulatorRunner.BootEmulatorAsync, fixing two issues discovered while investigating dotnet/android#10965.

Related PRs:

Problem 1: No early failure detection

The boot polling loop had no check for emulatorProcess.HasExited. If the emulator fails immediately (e.g., insufficient disk space, missing AVD, bad config), the full 300s timeout is wasted before reporting failure.

Problem 2: macOS fork behavior

On macOS, the emulator binary forks the real QEMU process and the parent exits with code 0 immediately. Without handling this, any HasExited check would incorrectly treat a successful fork as a failure.

Fix

Check emulatorProcess.HasExited during polling:

  • Non-zero exit code → fail fast with LaunchFailed (real error)
  • Exit code 0 → continue polling (macOS fork, real emulator running as separate process)

Testing

  • All 10 EmulatorRunner tests pass
  • Full suite: 241 passed, 1 pre-existing env failure, 10 skipped (require device)
  • Verified end-to-end on macOS with emulator 36.4.10

Add early process exit detection in BootEmulatorAsync boot polling loop.
Previously, if the emulator failed immediately (e.g., insufficient disk
space, missing AVD), the full 300s timeout was wasted before reporting.

On macOS, the emulator binary forks the real QEMU process and the parent
exits with code 0 immediately. Only non-zero exit codes are treated as
immediate failures; exit code 0 continues polling since the real emulator
runs as a separate process.

Context: dotnet/android#10965

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho
Copy link
Member Author

Closing — changes cherry-picked directly into feature/emulator-runner branch (PR #284).

@rmarinho rmarinho closed this Mar 18, 2026
@rmarinho rmarinho deleted the dev/emulator-early-exit branch March 18, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant