From ce6e47177acba767bf3067961e825983295d6689 Mon Sep 17 00:00:00 2001 From: Xing Zheng Date: Wed, 20 Sep 2023 00:21:34 +0000 Subject: [PATCH] Add default wait timeout for attachments from ACS --- .../acs/session/attach_resource_responder.go | 17 ++++++++++++++--- .../acs/session/attach_resource_responder.go | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/attach_resource_responder.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/attach_resource_responder.go index 5d4fd38bf13..198ebc7913d 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/attach_resource_responder.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/attach_resource_responder.go @@ -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 { @@ -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), @@ -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 ") diff --git a/ecs-agent/acs/session/attach_resource_responder.go b/ecs-agent/acs/session/attach_resource_responder.go index 5d4fd38bf13..198ebc7913d 100644 --- a/ecs-agent/acs/session/attach_resource_responder.go +++ b/ecs-agent/acs/session/attach_resource_responder.go @@ -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 { @@ -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), @@ -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 ")