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 the id and bundle 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 a time.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.
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:
App.swift(or equivalent) to look like this:ios-deploylike this (again, replacing theidandbundlepath as appropriate):Commentary on the issue
This seems to be related to the timing between when:
--justlaunchflag), andApp.swift)The app will not crash if you do any of the following:
ios-deployios-deploywithout the--justlaunchflagios-deploythat adds atime.sleep(10)call above this lineNote that if you use Xcode 15 and a device running iOS 17 and use
devicectlthen the crash does not occur, so I am confident that it's something to do with whatios-deployis 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.12.2/Applications/Xcode-14.3.1.app/Contents/Developer