From 0f782636f1dd6ed6655e4c20c9c89e4a29473af7 Mon Sep 17 00:00:00 2001 From: Prateek Chaudhry Date: Thu, 15 Jun 2023 00:34:35 -0700 Subject: [PATCH] dont consume resources for acs stopped tasks --- agent/engine/docker_task_engine.go | 12 ++++++++++++ agent/engine/task_manager.go | 1 + 2 files changed, 13 insertions(+) diff --git a/agent/engine/docker_task_engine.go b/agent/engine/docker_task_engine.go index 5f4e86e018a..bd68010365e 100644 --- a/agent/engine/docker_task_engine.go +++ b/agent/engine/docker_task_engine.go @@ -392,6 +392,12 @@ func (engine *DockerTaskEngine) monitorQueuedTasks(ctx context.Context) { if err != nil { break } + taskDesiredStatus := task.GetDesiredStatus() + if taskDesiredStatus.Terminal() { + logger.Info("Task desired status STOPPED while waiting for host resources, progressing without consuming resources", logger.Fields{field.TaskARN: task.Arn}) + engine.returnWaitingTask() + continue + } taskHostResources := task.ToHostResources() consumed, err := task.engine.hostResourceManager.consume(task.Arn, taskHostResources) if err != nil { @@ -409,6 +415,12 @@ func (engine *DockerTaskEngine) monitorQueuedTasks(ctx context.Context) { } } +// To be called when resources are not to be consumed by host resource manager, just dequeues and returns +func (engine *DockerTaskEngine) returnWaitingTask() { + task, _ := engine.dequeueTask() + task.consumedHostResourceEvent <- struct{}{} +} + func (engine *DockerTaskEngine) failWaitingTask(err error) { task, _ := engine.dequeueTask() logger.Error(fmt.Sprintf("Error consuming resources due to invalid task config : %s", err.Error()), logger.Fields{field.TaskARN: task.Arn}) diff --git a/agent/engine/task_manager.go b/agent/engine/task_manager.go index 13f7dcc0991..8015c4a23b3 100644 --- a/agent/engine/task_manager.go +++ b/agent/engine/task_manager.go @@ -204,6 +204,7 @@ func (mtask *managedTask) overseeTask() { // - Waits until host resource manager succesfully 'consume's task resources and returns // - For tasks which have crossed this stage before (on agent restarts), resources are pre-consumed - returns immediately // - If the task is already stopped (knownStatus is STOPPED), does not attempt to consume resources - returns immediately + // - If an ACS StopTask arrives, host resources manager returns immediately. Host resource manager does not consume resources // (resources are later 'release'd on Stopped task emitTaskEvent call) mtask.waitForHostResources()