Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using force detach of ENIs #458

Merged
merged 1 commit into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,22 +731,31 @@ func (cache *EC2InstanceMetadataCache) FreeENI(eniName string) error {
log.Errorf("Failed to retrieve ENI %s attachment id: %v", eniName, err)
return errors.Wrap(err, "FreeENI: failed to retrieve ENI's attachment id")
}

log.Debugf("Found ENI %s attachment id: %s ", eniName, aws.StringValue(attachID))

// Detach it first
detachInput := &ec2.DetachNetworkInterfaceInput{
AttachmentId: attachID,
Force: aws.Bool(true),
}

start := time.Now()
_, err = cache.ec2SVC.DetachNetworkInterface(detachInput)
awsAPILatency.WithLabelValues("DetachNetworkInterface", fmt.Sprint(err != nil)).Observe(msSince(start))
if err != nil {
awsAPIErrInc("DetachNetworkInterface", err)
log.Errorf("Failed to detach ENI %s %v", eniName, err)
return errors.Wrap(err, "FreeENI: failed to detach ENI from instance")
// Retry detaching the ENI from the instance
var retry int
for retry = 0; retry <= maxENIDeleteRetries; retry++ {
start := time.Now()
_, err = cache.ec2SVC.DetachNetworkInterface(detachInput)
awsAPILatency.WithLabelValues("DetachNetworkInterface", fmt.Sprint(err != nil)).Observe(msSince(start))
if err != nil {
awsAPIErrInc("DetachNetworkInterface", err)
log.Errorf("Failed to detach ENI %s %v", eniName, err)
if retry == maxENIDeleteRetries {
return errors.New("unable to detach ENI from EC2 instance, giving up")
}
} else {
log.Infof("Successfully detached ENI: %s", eniName)
break
}

log.Debugf("Not able to detach ENI yet (attempt %d/%d): %v ", retry, maxENIDeleteRetries, err)
time.Sleep(retryDeleteENIInternal)
}

// It may take awhile for EC2-VPC to detach ENI from instance
Expand Down