Skip to content

Commit

Permalink
added retries in case if git command returns nil status (breoken pipe?)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Apr 10, 2024
1 parent 39f3f3c commit 617345b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/datadog/ci/git/local_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,20 @@ def exec_git_command(cmd, stdin: nil)
# no-dd-sa:ruby-security/shell-injection
out, status = Open3.capture2e(cmd, stdin_data: stdin)

raise "Failed to run git command #{cmd}: #{out}" unless status.success?
if status.nil?
retry_count = 5
Datadog.logger.debug { "Opening pipe failed, starting retries..." }
while status.nil? && retry_count.positive?
# no-dd-sa:ruby-security/shell-injection
out, status = Open3.capture2e(cmd, stdin_data: stdin)
Datadog.logger.debug { "After retry status is [#{status}]" }
retry_count -= 1
end
end

if status.nil? || !status.success?
raise "Failed to run git command [#{cmd}] with input [#{stdin}] and output [#{out}]"
end

# Sometimes Encoding.default_external is somehow set to US-ASCII which breaks
# commit messages with UTF-8 characters like emojis
Expand All @@ -213,7 +226,7 @@ def exec_git_command(cmd, stdin: nil)

def log_failure(e, action)
Datadog.logger.debug(
"Unable to read #{action}: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
"Unable to perform #{action}: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
)
end
end
Expand Down

0 comments on commit 617345b

Please sign in to comment.