Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug where container state change was not submitted under race condition #1067

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

## 1.15.1
* Bug - Fixed a bug where container state information wasn't reported. [#1067](https://github.com/aws/amazon-ecs-agent/pull/1067)
* Bug - Fixed a bug where a task can be blocked in creating state. [#1048](https://github.com/aws/amazon-ecs-agent/pull/1048)
* Bug - Fixed dynamic HostPort in container metadata. [#1052](https://github.com/aws/amazon-ecs-agent/pull/1052)

Expand Down
4 changes: 2 additions & 2 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ func (client *APIECSClient) SubmitTaskStateChange(change api.TaskStateChange) er
return errors.New("ecs api client: SubmitTaskStateChange called with an invalid change")
}

if change.Status != api.TaskRunning && change.Status != api.TaskStopped {
if change.Status != api.TaskRunning && change.Status != api.TaskStopped && len(change.Containers) == 0 {
seelog.Debugf("Not submitting unsupported upstream task state: %s", change.Status.String())
// Not really an error
return nil
}

status := change.Status.String()
status := change.Status.BackendStatus()

req := ecs.SubmitTaskStateChangeInput{
Cluster: aws.String(client.config.Cluster),
Expand Down
40 changes: 39 additions & 1 deletion agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ func TestSubmitTaskStateChangeWithAttachments(t *testing.T) {
assert.NoError(t, err, "Unable to submit task state change with attachments")
}

//
func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand All @@ -696,3 +695,42 @@ func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
})
assert.NoError(t, err, "Unable to submit task state change with no attachments")
}

// TestSubmitContainerStateChangeWhileTaskInPending tests the container state change was submitted
// when the task is still in pending state
func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
ecs.SubmitTaskStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
Status: strptr("PENDING"),
Reason: strptr(""),
Containers: []*ecs.ContainerStateChange{
{
ContainerName: strptr("container"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{},
},
},
},
})

taskStateChangePending := api.TaskStateChange{
Status: api.TaskCreated,
TaskARN: "arn",
Containers: []api.ContainerStateChange{
{
TaskArn: "arn",
ContainerName: "container",
Status: api.ContainerRunning,
},
},
}

err := client.SubmitTaskStateChange(taskStateChangePending)
assert.NoError(t, err)
}