Repository navigation
Conversation
BundleIdentifierResolver.runLaunchctlList created a stdout and a stderr Pipe for `simctl spawn <udid> launchctl list` and never closed their read ends. The long-lived daemon reads the process list before every iOS command (liveness probe) and again for `ui` / `app-state`, so it leaked two descriptors per read until spawning failed and every process-list read broke until the daemon restarted. Close both read ends with `defer` on every path. The runner is factored into runCapturing(executable:arguments:timeout:makePipe:) so a test can check, pipe by pipe, that both read ends are closed after a successful and a failing child. Signed-off-by: DMY <147dmy@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BundleIdentifierResolver.runLaunchctlListcreates a stdout and a stderrPipeforxcrun simctl spawn <udid> launchctl listand never closes their read ends. In a one-shot CLI process that does not matter. The per-simulator daemon is long-lived, though, and it leaks two descriptors on every process-list read:uireuses that snapshot or reads the list itself, andapp-statereads it too.So the leak grows with the number of commands. Once the daemon reaches its descriptor limit, spawning fails. After that,
uireturns an emptyappPackageandapp-stateanswers "Could not read the running-process list" until the daemon is restarted. I hit this after roughly a thousand commands in one long automation session.Reproduction
Booted iPhone 17 Pro simulator, iOS 26.5, Xcode 27.1, with Settings in the foreground. Any daemon-routed iOS command works;
uiis shown here:Measured with a debug build of each revision. Values are
lsof -p <daemon pid> | wc -l, with the number ofPIPErows in parentheses:uicallsmainEvery
uicall adds exactly two pipe descriptors onmain.Fix
Close both read ends with
defer, so they are closed on every path: success, non-zero exit and timeout. The runner is factored intorunCapturing(executable:arguments:timeout:makePipe:)so it can be tested without a simulator.runLaunchctlListkeeps its behaviour and its 5 s timeout.Tests
BundleIdentifierResolverProcessTestsruns/bin/echoand a failing/bin/sh -c 'echo oops >&2; exit 3'. ThroughmakePipeit records each read end's descriptor and inode, then checks that neither is still open after the call. The check is per pipe on purpose. A first version counted the process's open descriptors, and that was flaky undermake test, because other suites open descriptors in parallel. A descriptor number that another pipe reuses has a different inode, so the reuse is not mistaken for a leak.defer, both cases fail ("read end N is still open"). With it, they pass.make testpasses on macOS with Xcode 27.1: 1272 Swift Testing tests and 231 XCTest tests.make e2e-iospasses on an iPhone 17 Pro simulator (iOS 26.5): 29 test runs, 0 failures (6 known issues, as onmain).Side note (not changed here)
stdout is read only after the child exits. Output larger than the pipe buffer (~64 KB) would block the child until the timeout.
launchctl listis far below that today, so I left it alone.