Skip to content

Commit 6ce81f9

Browse files
Anandaraju Coimbatore Sivarajumwjones-aws
authored andcommitted
Add retry with exponential backoff for install script while downloading version file from S3
Why is this change needed? --------- Prior to this change, install script sometimes fails when S3 connection is timedout while downloading version file. This happens when there is a new region build. But when the s3 download is retried it works fine. so added retry logic to not fail in the first attempt. How does it address the issue? --------- This change added retry logic to not fail in the first attempt.
1 parent dd0848c commit 6ce81f9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bin/install

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ EOF
397397
package_file.write(s3.read)
398398
end
399399
rescue *exceptions => e
400-
@log.error("Could not find package to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
400+
@log.warn("Could not find package to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
401401
if (retries < 5)
402402
sleep 2 ** retries
403403
retries += 1
@@ -415,14 +415,23 @@ end
415415
uri = s3_bucket.object_uri(key)
416416
@log.info("Endpoint: #{uri}")
417417

418+
retries ||= 0
419+
exceptions = [OpenURI::HTTPError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT]
418420
begin
419421
require 'json'
420422

421423
version_string = uri.read(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120, :proxy => @http_proxy)
422424
JSON.parse(version_string)
423-
rescue OpenURI::HTTPError => e
424-
@log.error("Could not find version file to download at '#{uri.to_s}'")
425-
exit(1)
425+
rescue *exceptions => e
426+
@log.warn("Could not find version file to download at '#{uri.to_s}' - Retrying... Attempt: '#{retries.to_s}'")
427+
if (retries < 5)
428+
sleep 2 ** retries
429+
retries += 1
430+
retry
431+
else
432+
@log.error("Could not download CodeDeploy Agent version file. Exiting Install script.")
433+
exit(1)
434+
end
426435
end
427436
end
428437

0 commit comments

Comments
 (0)