hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.04k stars 3.32k forks source link

builder/amazon: make resilient AWS API calls #559

Closed mwhooker closed 10 years ago

mwhooker commented 10 years ago

aws api call may fail, so it's good practice to retry them a couple of times in case of intermittent failure. See amazon's documentation on the subject here http://docs.aws.amazon.com/general/latest/gr/api-retries.html

mwhooker commented 10 years ago

I think a wise way to go about this is by using a retrying http transport. I will implement this using http://github.com/daaku/go.httpcontrol. Transport is a nice interface, so we can swap it out down the road if we need to.

mwhooker commented 10 years ago

I've started implementing this here https://github.com/mwhooker/packer

I get the feeling the retry logic might need to be changed.

go.httpcontrol (rightly) refuses to retry non-GET requests and non-temporary network failures.

Amazon however allows mutating actions via HTTP GET requests, and supports idempotence at the application level

go.httpcontrol also does not provide exponential backoff.

I propose changing the retry logic to something like

retries = 0

DO
    wait for (2^retries * 100) milliseconds

    http_status, err = Make request.

    IF http_status = SUCCESS
        retry = false
    ELSE IF err.Temporary = true
        retry = true
    ELSE IF http_status = 4xxx
        retry = true
    ELSE
        Some other error occurred, so stop calling the API.
        retry = false
    END IF

    retries = retries + 1

WHILE (retry AND (retries < MAX_RETRIES))

perhaps the best method would be plugable retry logic

mwhooker commented 10 years ago

The above psuedocode is implemented in my fork of go.httpcontrol

mitchellh commented 10 years ago

I'll review your amz stuff over there.

mitchellh commented 10 years ago

Done.