Skip to content

Commit 9945a09

Browse files
authored
Merge pull request #4361 from DataDog/tonycthsu/jruby-92-bundle-install-flake
Retry `bundle install` flakiness for JRuby 9.2
2 parents 5319afc + ffaeb2e commit 9945a09

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tasks/github.rake

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,20 @@ namespace :github do
355355
tasks.each do |task|
356356
env = { 'BUNDLE_GEMFILE' => task['gemfile'] }
357357
cmd = 'bundle check || bundle install'
358-
Bundler.with_unbundled_env { sh(env, cmd) }
358+
359+
if RUBY_PLATFORM == 'java' && RUBY_ENGINE_VERSION.start_with?('9.2')
360+
# For JRuby 9.2, the `bundle install` command failed ocassionally with the NameError.
361+
#
362+
# Mitigate the flakiness by retrying the command up to 3 times.
363+
#
364+
# https://github.com/jruby/jruby/issues/7508
365+
# https://github.com/jruby/jruby/issues/3656
366+
with_retry do
367+
Bundler.with_unbundled_env { sh(env, cmd) }
368+
end
369+
else
370+
Bundler.with_unbundled_env { sh(env, cmd) }
371+
end
359372
end
360373
end
361374

@@ -369,5 +382,21 @@ namespace :github do
369382
Bundler.with_unbundled_env { sh(env, cmd) }
370383
end
371384
end
385+
386+
def with_retry(&block)
387+
retries = 0
388+
begin
389+
yield
390+
rescue StandardError => e
391+
rake_output_message(
392+
"Bundle install failure (Attempt: #{retries + 1}): #{e.class.name}: #{e.message}, \
393+
Source:\n#{Array(e.backtrace).join("\n")}"
394+
)
395+
sleep(2**retries)
396+
retries += 1
397+
retry if retries < 3
398+
raise
399+
end
400+
end
372401
end
373402
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)