Description
Expected behavior
The app can print to stdout without the app crashing.
Actual behavior.
The app immediately crashes when attempting to write to stdout.
Steps to reproduce the problem
See steps in this repo, otherwise:
- Create a new iOS app.
- Update
App.swift
(or equivalent) to look like this:
import SwiftUI
@main
struct iOSDeployCrashApp: App {
init() {
FileHandle.standardOutput.write("crash causer".data(using: .utf8)!)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
- Build the iOS app using a command like this (replacing the project and scheme names as appropriate):
xcodebuild -derivedDataPath ios/DerivedData -project ios-deploy-stdout-crash/ios-deploy-stdout-crash.xcodeproj -scheme ios-deploy-stdout-crash -destination generic/platform=iOS
- Launch the app using
ios-deploy
like this (again, replacing theid
andbundle
path as appropriate):
ios-deploy \
--id "00008030-XXXXXXXXXXXXX" \
--bundle "ios/DerivedData/Build/Products/Debug-iphoneos/ios-deploy-stdout-crash.app" \
--justlaunch
Commentary on the issue
This seems to be related to the timing between when:
- the process detaches (because of the
--justlaunch
flag), and - the iOS app first tries to print to stdout (see
App.swift
)
The app will not crash if you do any of the following:
- comment out the line where the app tries to write to stdout, or
- launch the app via a method other than
ios-deploy
- launch the app via
ios-deploy
without the--justlaunch
flag - use a build of
ios-deploy
that adds atime.sleep(10)
call above this line
Note that if you use Xcode 15 and a device running iOS 17 and use devicectl
then the crash does not occur, so I am confident that it's something to do with what ios-deploy
is doing in terms of stdout/stderr.
The actual error that ends up getting thrown is errno 5 (EIO)
.
Maybe it's something to do with how the process is being detached and the state of the various pipes involved at that point?
System Specs
Please run the commands below in your Terminal.app and include it in the issue. Check when done and include results below.
- 1. system_profiler SPSoftwareDataType
Software: System Software Overview: System Version: macOS 13.6 (22G120) Kernel Version: Darwin 22.6.0 Boot Volume: Macintosh HD Boot Mode: Normal Computer Name: DTO-A026 User Name: Ham Chapman (ham) Secure Virtual Memory: Enabled System Integrity Protection: Enabled Time since boot: 3 days, 18 hours, 14 minutes
- 2. ios-deploy -V:
1.12.2
- 3. xcodebuild -version:
/Applications/Xcode-14.3.1.app/Contents/Developer
- 4. xcode-select --print-path
Xcode 14.3.1 Build version 14E300c
- 5. gcc --version:
Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: arm64-apple-darwin22.6.0 Thread model: posix InstalledDir: /Applications/Xcode-14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
- 6. lldb --version:
lldb-1403.0.17.67 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
- If using NodeJS/npm: (N/A)
- 7. npm -v
- 8. node -v