Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App launched with --justlaunch immediately crashes when trying to print to stdout #594

Open
6 of 9 tasks
hamchapman opened this issue Sep 25, 2023 · 2 comments
Open
6 of 9 tasks

Comments

@hamchapman
Copy link

hamchapman commented Sep 25, 2023

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:

  1. Create a new iOS app.
  2. 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()
        }
    }
}
  1. 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
  1. 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.

  • 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
@pothurajtharun
Copy link

Even I'm facing the same issue, before deatch the process it should wait for some time. Can someone please look into it ? Thanks!

@diegodorado
Copy link

Having the same issue

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

No branches or pull requests

3 participants