Skip to content

Commit

Permalink
Fix: resolve deadlock in LatestOsVersion#version_for_os
Browse files Browse the repository at this point in the history
LatestOsVersion#version_for_os can be catched in a deadlock when
used with Xcode 13.3.0 or later while a device is physically connected
to the computer.

In this case, xcodebuild will return a few lines of errors on stderr
which will trigger a deadlock in Open3#open3.  The problem is
mentioned explicitely in the documentation of Open3#open3:

> You should be careful to avoid deadlocks. Since pipes are fixed
> length buffer, #popen3(“prog”) {|i, o, e, t| o.read } deadlocks if
> the program generates many output on stderr. You should be read
> stdout and stderr simultaneously (using thread or IO.select). However
> if you don't need stderr output, #popen2 can be used. If merged
> stdout and stderr output is not a problem, you can use #popen2e.
> If you really needs stdout and stderr output as separate strings,
> you can consider #capture3.

Using Open3#capture2 or Open3#open2 would show the error in the
terminal, but Open3#capture3 allows us to capture only stdout and
hide stderr from the users eyes.
  • Loading branch information
stbix committed May 26, 2022
1 parent 3bbaf61 commit 3fe8787
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions snapshot/lib/snapshot/latest_os_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ def self.version(os)
def self.version_for_os(os)
# We do all this, because we would get all kind of crap output generated by xcodebuild
# so we need to ignore stderror
output = ''
Open3.popen3('xcodebuild -version -sdk') do |stdin, stdout, stderr, wait_thr|
output = stdout.read
end
stdout, _stderr, _status = Open3.capture3('xcodebuild -version -sdk')

matched = output.match(/#{os} ([\d\.]+) \(.*/)
matched = stdout.match(/#{os} ([\d\.]+) \(.*/)
if matched.nil?
FastlaneCore::UI.user_error!("Could not determine installed #{os} SDK version. Try running the _xcodebuild_ command manually to ensure it works.")
elsif matched.length > 1
Expand Down

0 comments on commit 3fe8787

Please sign in to comment.