From e40595fa57181e6c504c6de91dee7b80fcda0419 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Fri, 11 Mar 2016 11:24:25 -0500 Subject: [PATCH] AWS volumes: Release disk from attaching map on error If AWS gives us an actual error (vs just timing out), we know the disk did not attach, and so we can remove it immediately from the attaching map. --- pkg/cloudprovider/providers/aws/aws.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 5d6107542fc..cba7eed90cb 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -1144,6 +1144,8 @@ func (self *awsDisk) describeVolume() (*ec2.Volume, error) { return volumes[0], nil } +// waitForAttachmentStatus polls until the attachment status is the expected value +// TODO(justinsb): return (bool, error) func (self *awsDisk) waitForAttachmentStatus(status string) error { // TODO: There may be a faster way to get this when we're attaching locally attempt := 0 @@ -1278,9 +1280,11 @@ func (c *AWSCloud) AttachDisk(diskName string, instanceName string, readOnly boo ec2Device = "/dev/sd" + string(mountDevice) } - attached := false + // attachEnded is set to true if the attach operation completed + // (successfully or not) + attachEnded := false defer func() { - if attached { + if attachEnded { awsInstance.endAttaching(disk.awsID, mountDevice) } }() @@ -1294,6 +1298,7 @@ func (c *AWSCloud) AttachDisk(diskName string, instanceName string, readOnly boo attachResponse, err := c.ec2.AttachVolume(request) if err != nil { + attachEnded = true // TODO: Check if the volume was concurrently attached? return "", fmt.Errorf("Error attaching EBS volume: %v", err) } @@ -1306,7 +1311,7 @@ func (c *AWSCloud) AttachDisk(diskName string, instanceName string, readOnly boo return "", err } - attached = true + attachEnded = true return hostDevice, nil }