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

os/linux/ld: harden brewed_ld_so_diagnostics against TypeError #18333

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Library/Homebrew/os/linux/ld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
module Ld
sig { returns(String) }
def self.brewed_ld_so_diagnostics
@brewed_ld_so_diagnostics ||= T.let({}, T.nilable(T::Hash[Pathname, T.nilable(String)]))

brewed_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
return "" unless brewed_ld_so.exist?

ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics")
return "" unless $CHILD_STATUS.success?
brewed_ld_so_target = brewed_ld_so.readlink
@brewed_ld_so_diagnostics[brewed_ld_so_target] ||= begin
ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics")
ld_so_output if $CHILD_STATUS.success?
end

@brewed_ld_so_diagnostics[brewed_ld_so_target].to_s
rescue TypeError
# Workaround for intermittent `Error: no implicit conversion of false into String`
carlocab marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/Homebrew/brew/issues/17828
unless @retried_brewed_ld_so_diagnostics&.fetch(brewed_ld_so_target, false)
@retried_brewed_ld_so_diagnostics ||= T.let({}, T.nilable(T::Hash[Pathname, T::Boolean]))
@retried_brewed_ld_so_diagnostics[brewed_ld_so_target] = true
sleep 0.5
carlocab marked this conversation as resolved.
Show resolved Hide resolved
retry

Check warning on line 29 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L27-L29

Added lines #L27 - L29 were not covered by tests
end

ld_so_output
raise

Check warning on line 32 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L32

Added line #L32 was not covered by tests
end

sig { returns(String) }
Expand Down