`ios_xctestrun_runner` skips the simulator cleanup action on early exits and signals

Open
#3,163 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@katre is already working on this.

Since Dec 2, 2026.

  • #3164 by @katre — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bash, shell
Domain
mobile, testing

Research direction

Start with ios_xctestrun_runner.template.sh and trace its exit paths, signal handling, and the existing clean_up_simulator_action call. Check the runner’s tests for coverage of early exits and signals, then reproduce with a failing pre_action as described. Done means cleanup runs exactly once for each created simulator and the runner preserves its original exit status.

Written by the indexing model from the issue text.

Description

ios_xctestrun_runner.template.sh runs clean_up_simulator_action as an
ordinary statement near the end of the script. The runner uses
set -euo pipefail and has several exit calls, so any exit before that line
skips cleanup and leaks the simulator the runner created. With the default
cleanup action and reuse_simulator = False, every one of these leaves a
simulator behind. With a custom create/cleanup pair (for example, one that
leases simulators from a pool), the lease is never released.

Exit paths that skip cleanup today:

  • The pre_action exits nonzero (set -e aborts the runner).
  • The post_action fails with post_action_determines_exit_code = True (the
    runner exits before cleanup).
  • A configuration error after the simulator is created, such as
    screen_capture_format with attachment_lifetime = "keepNever", or x86_64
    tests on arm64 without a test host.
  • Any command that set -e aborts on, such as xcrun llvm-profdata merge
    during coverage.
  • Signals, including the SIGTERM Bazel sends when a test times out.
Steps to reproduce
  1. Define an ios_xctestrun_runner with reuse_simulator = False and a
    pre_action that runs exit 1.
  2. Run an ios_unit_test with that runner.
  3. Run xcrun simctl list devices: the simulator the runner created is still
    there.
Expected

The cleanup action runs exactly once for every simulator the runner creates,
whichever way the runner exits, and the runner keeps its original exit status.

Known limitations

SIGKILL can't be trapped, so a hard kill after the timeout grace period still
skips cleanup. Callers that need a guarantee should also release simulators
outside the test action.

Dominant language
Starlark
Stars
600
Forks
354
Avg merge
2d 7h
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_apple

All issues in bazelbuild/rules_apple

Similar issues

More Mobile Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.