Skip to content
Closed
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
11 changes: 11 additions & 0 deletions agent/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ func (tm *taskManager) run(ctx context.Context) {
}
case <-shutdown:
if cancel != nil {
// Wait for operation to finish if the task
// is in preparing state. This avoid the race
// between Prepare and Remove operations,
// which could cause orphan containers.
if tm.task.Status.State == api.TaskStatePreparing {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should never be looking at task state to make decisions about what to do. State is only inspected or mutated in exec.Do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's better doing it in exec.Do so that it can go through the state machine. I thought about it but I didn't figure out how. It looks the shutdown is handled as an special event which can abort other ongoing activities for the same task.

select {
case <-errs:
case <-statusq:
}
}

// cancel outstanding operation.
cancel()
}
Expand Down