diff --git a/tasks/github.rake b/tasks/github.rake index 03853842dad..eb60f0bf46a 100644 --- a/tasks/github.rake +++ b/tasks/github.rake @@ -355,7 +355,20 @@ namespace :github do tasks.each do |task| env = { 'BUNDLE_GEMFILE' => task['gemfile'] } cmd = 'bundle check || bundle install' - Bundler.with_unbundled_env { sh(env, cmd) } + + if RUBY_PLATFORM == 'java' && RUBY_ENGINE_VERSION.start_with?('9.2') + # For JRuby 9.2, the `bundle install` command failed ocassionally with the NameError. + # + # Mitigate the flakiness by retrying the command up to 3 times. + # + # https://github.com/jruby/jruby/issues/7508 + # https://github.com/jruby/jruby/issues/3656 + with_retry do + Bundler.with_unbundled_env { sh(env, cmd) } + end + else + Bundler.with_unbundled_env { sh(env, cmd) } + end end end @@ -369,5 +382,21 @@ namespace :github do Bundler.with_unbundled_env { sh(env, cmd) } end end + + def with_retry(&block) + retries = 0 + begin + yield + rescue StandardError => e + rake_output_message( + "Bundle install failure (Attempt: #{retries + 1}): #{e.class.name}: #{e.message}, \ + Source:\n#{Array(e.backtrace).join("\n")}" + ) + sleep(2**retries) + retries += 1 + retry if retries < 3 + raise + end + end end # rubocop:enable Metrics/BlockLength