Skip to content

Commit 61371b4

Browse files
committed
engine: Simplify code in mtask.cleanupTask
1 parent d113ab4 commit 61371b4

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

agent/engine/dockerstate/docker_task_engine_state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (state *DockerTaskEngineState) AddImageState(imageState *image.ImageState)
225225
}
226226

227227
// RemoveTask removes a task from this state. It removes all containers and
228-
// other associated metadata. It does aquire the write lock.
228+
// other associated metadata. It does acquire the write lock.
229229
func (state *DockerTaskEngineState) RemoveTask(task *api.Task) {
230230
state.lock.Lock()
231231
defer state.lock.Unlock()

agent/engine/task_manager.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,12 @@ func (mtask *managedTask) cleanupTask(taskStoppedDuration time.Duration) {
507507
// For the duration of this, simply discard any task events; this ensures the
508508
// speedy processing of other events for other tasks
509509
handleCleanupDone := make(chan struct{})
510-
go func() {
511-
mtask.engine.sweepTask(mtask.Task)
512-
mtask.engine.state.RemoveTask(mtask.Task)
513-
handleCleanupDone <- struct{}{}
514-
}()
515510
// discard events while the task is being removed from engine state
516-
mtask.discardEventsUntil(handleCleanupDone)
511+
go mtask.discardEventsUntil(handleCleanupDone)
512+
mtask.engine.sweepTask(mtask.Task)
513+
mtask.engine.state.RemoveTask(mtask.Task)
517514
log.Debug("Finished removing task data; removing from state no longer managing", "task", mtask.Task)
518515
// Now remove ourselves from the global state and cleanup channels
519-
go mtask.discardEventsUntil(handleCleanupDone) // keep discarding events until the task is fully gone
520516
mtask.engine.processTasks.Lock()
521517
delete(mtask.engine.managedTasks, mtask.Arn)
522518
handleCleanupDone <- struct{}{}

0 commit comments

Comments
 (0)