Commit e17984fa authored by Patrick Lucas's avatar Patrick Lucas

Fix race condition after launching EC2 instance

It is possible for an instance to not immediately exist after it is
launched. Previously, InstanceStateRefreshFunc would crash if this race
condition were realized.

This change takes the exact same approach of the function above,
AMIStateRefreshFunc, treating 'InvalidInstanceID.NotFound' as if there
were an empty result.
parent 94487871
...@@ -62,11 +62,16 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc { ...@@ -62,11 +62,16 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) StateRefreshFunc {
return func() (interface{}, string, error) { return func() (interface{}, string, error) {
resp, err := conn.Instances([]string{i.InstanceId}, ec2.NewFilter()) resp, err := conn.Instances([]string{i.InstanceId}, ec2.NewFilter())
if err != nil { if err != nil {
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) log.Printf("Error on InstanceStateRefresh: %s", err)
return nil, "", 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 // Sometimes AWS just has consistency issues and doesn't see
// our instance yet. Return an empty state. // our instance yet. Return an empty state.
return nil, "", nil return nil, "", nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment