Skip to content

Commit

Permalink
Merge pull request hashicorp#522 from patricklucas/fix_instance_not_f…
Browse files Browse the repository at this point in the history
…ound_race

builder/amzon: fix race condition after launching EC2 instance
  • Loading branch information
mitchellh committed Oct 14, 2013
2 parents eb2bcfe + aeb0e8b commit 54e1f70
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions builder/amazon/common/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := conn.Instances([]string{i.InstanceId}, ec2.NewFilter())
if err != nil {
log.Printf("Error on InstanceStateRefresh: %s", err)
return nil, "", err
if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidInstanceID.NotFound" {
// Set this to nil as if we didn't find anything.
resp = nil
} else {
log.Printf("Error on InstanceStateRefresh: %s", err)
return nil, "", err
}
}

if len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
if resp == nil || len(resp.Reservations) == 0 || len(resp.Reservations[0].Instances) == 0 {
// Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state.
return nil, "", nil
Expand Down

0 comments on commit 54e1f70

Please sign in to comment.