From bb20b3c720e59d5ef6b2a86c8e98a8d6e828b07a Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:44:11 +0800 Subject: [PATCH 1/3] os/linux/ld: harden `brewed_ld_so_diagnostics` against `TypeError` I think this is a bug in Ruby, but I've no idea how to track it down. I can reproduce it intermittently in a codespace when `brew install`ing a large number of formulae. To work around this: - cache the return value of `brewed_ld_so_diagnostics` so that we can limit the number of calls to `IO.popen` - retry once when we see a `TypeError` Closes #17828. --- Library/Homebrew/os/linux/ld.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/os/linux/ld.rb b/Library/Homebrew/os/linux/ld.rb index 3dc85cb23e119..f9c782bf50940 100644 --- a/Library/Homebrew/os/linux/ld.rb +++ b/Library/Homebrew/os/linux/ld.rb @@ -7,13 +7,28 @@ module Linux 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` + 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 + retry + end - ld_so_output + raise end sig { returns(String) } From 70ab4932d323054916ca35cf0e58486c4f67638d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 17 Sep 2024 01:03:34 +0800 Subject: [PATCH 2/3] Add link to issue with context --- Library/Homebrew/os/linux/ld.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/os/linux/ld.rb b/Library/Homebrew/os/linux/ld.rb index f9c782bf50940..dbc92de72db9c 100644 --- a/Library/Homebrew/os/linux/ld.rb +++ b/Library/Homebrew/os/linux/ld.rb @@ -21,6 +21,7 @@ def self.brewed_ld_so_diagnostics @brewed_ld_so_diagnostics[brewed_ld_so_target].to_s rescue TypeError # Workaround for intermittent `Error: no implicit conversion of false into String` + # 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 From 1656d08629b3582f2593c478a157f16eb62eca67 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:51:27 +0800 Subject: [PATCH 3/3] os/linux/ld: drop `retry` logic This is a hack, so let's see if we can get away with skipping it for now. --- Library/Homebrew/os/linux/ld.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Library/Homebrew/os/linux/ld.rb b/Library/Homebrew/os/linux/ld.rb index dbc92de72db9c..9227792b29920 100644 --- a/Library/Homebrew/os/linux/ld.rb +++ b/Library/Homebrew/os/linux/ld.rb @@ -7,7 +7,7 @@ module Linux 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_diagnostics ||= T.let({}, T.nilable(T::Hash[Pathname, String])) brewed_ld_so = HOMEBREW_PREFIX/"lib/ld.so" return "" unless brewed_ld_so.exist? @@ -19,17 +19,6 @@ def self.brewed_ld_so_diagnostics end @brewed_ld_so_diagnostics[brewed_ld_so_target].to_s - rescue TypeError - # Workaround for intermittent `Error: no implicit conversion of false into String` - # 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 - retry - end - - raise end sig { returns(String) }