Skip to content

Commit

Permalink
Add default wait timeout for attachments from ACS
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx0624 committed Sep 20, 2023
1 parent dd25e3f commit ce6e471
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions ecs-agent/acs/session/attach_resource_responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (

const (
AttachResourceMessageName = "ConfirmAttachmentMessage"
// DefaultAttachmentWaitTimeoutInMs is the default timeout, 5 minutes, for handling the attachments from ACS.
DefaultAttachmentWaitTimeoutInMs = 300000
)

type ResourceHandler interface {
Expand Down Expand Up @@ -78,8 +80,17 @@ func (r *attachResourceResponder) handleAttachMessage(message *ecsacs.ConfirmAtt
}

messageID := aws.StringValue(message.MessageId)
expiresAt := receivedAt.Add(
time.Duration(aws.Int64Value(message.WaitTimeoutMs)) * time.Millisecond)
// Set a default wait timeout (5m) for the attachment message from ACS if not provided.
// For example, the attachment payload for the EBS attach might not have the property.
waitTimeoutMs := aws.Int64Value(message.WaitTimeoutMs)
if waitTimeoutMs == 0 {
waitTimeoutMs = DefaultAttachmentWaitTimeoutInMs
}
logger.Debug("Waiting for the resource attachment to be ready",
logger.Fields{
"WaitTimeoutMs": waitTimeoutMs,
})
expiresAt := receivedAt.Add(time.Duration(waitTimeoutMs) * time.Millisecond)
go r.resourceHandler.HandleResourceAttachment(&resource.ResourceAttachment{
AttachmentInfo: attachmentinfo.AttachmentInfo{
TaskARN: aws.StringValue(message.TaskArn),
Expand Down Expand Up @@ -194,7 +205,7 @@ func validateAttachmentAndReturnProperties(message *ecsacs.ConfirmAttachmentMess
return attachmentProperties, nil
}

// For "EphemeralStorage" and "ElasticBlockStorage", ACS is using resourceType to indicate its attachment type.
// For legacy EBS volumes("EphemeralStorage" and "ElasticBlockStorage"), ACS is using resourceType to indicate its attachment type.
err = resource.ValidateResourceByResourceType(attachmentProperties)
if err != nil {
return nil, errors.Wrap(err, "resource attachment validation by resource type failed ")
Expand Down

0 comments on commit ce6e471

Please sign in to comment.