Skip to content

Commit 617345b

Browse files
committed
added retries in case if git command returns nil status (breoken pipe?)
1 parent 39f3f3c commit 617345b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/datadog/ci/git/local_repository.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,20 @@ def exec_git_command(cmd, stdin: nil)
195195
# no-dd-sa:ruby-security/shell-injection
196196
out, status = Open3.capture2e(cmd, stdin_data: stdin)
197197

198-
raise "Failed to run git command #{cmd}: #{out}" unless status.success?
198+
if status.nil?
199+
retry_count = 5
200+
Datadog.logger.debug { "Opening pipe failed, starting retries..." }
201+
while status.nil? && retry_count.positive?
202+
# no-dd-sa:ruby-security/shell-injection
203+
out, status = Open3.capture2e(cmd, stdin_data: stdin)
204+
Datadog.logger.debug { "After retry status is [#{status}]" }
205+
retry_count -= 1
206+
end
207+
end
208+
209+
if status.nil? || !status.success?
210+
raise "Failed to run git command [#{cmd}] with input [#{stdin}] and output [#{out}]"
211+
end
199212

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

214227
def log_failure(e, action)
215228
Datadog.logger.debug(
216-
"Unable to read #{action}: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
229+
"Unable to perform #{action}: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
217230
)
218231
end
219232
end

0 commit comments

Comments
 (0)