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

Reset agent state if the instance id changed on agent restart #892

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

richardpen
Copy link

@richardpen richardpen commented Jul 18, 2017

Summary

Fix #859

Implementation details

Rest the agent state when detected the instance id is different from the one stored in the agent state file.

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass
  • Manually tested
    New tests cover the changes:

Description for the changelog

Licensing

This contribution is under the terms of the Apache 2.0 License:
yes

@@ -96,6 +98,18 @@ func newDockerTaskEngineState() *DockerTaskEngineState {
}
}

// Reset resets all the states
func (state *DockerTaskEngineState) Reset() {
state.lock.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Lock and Unlock instead of RLock and RUnlock

@@ -232,6 +232,8 @@ func (agent *ecsAgent) newTaskEngine(containerChangeEventStream *eventstream.Eve
log.Warnf(instanceIDMismatchErrorFormat,
previousEC2InstanceID, currentEC2InstanceID)

// Reset agent state as a new container instance
state.Reset()
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like you'd need to invoke statemanager.Save() here as well? Otherwise, an agent restart here may still result in the wrong state, yes?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think so, the file will be override later. And if agent restart at this point, it will run into the same code path state.Reset will be executed again.

@@ -96,6 +98,18 @@ func newDockerTaskEngineState() *DockerTaskEngineState {
}
}

// Reset resets all the states
func (state *DockerTaskEngineState) Reset() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you modify this so that you extract all the state.xxx=make() bits into a new method, and invoke it here and from newDockerTaskEngineState() so that in future if we modify this struct to persist more state, there's no cognitive load of updating Reset method as well?

Copy link
Contributor

@aaithal aaithal left a comment

Choose a reason for hiding this comment

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

lgtm

@richardpen richardpen merged commit bd577e5 into aws:dev Aug 7, 2017
@jhaynes jhaynes mentioned this pull request Aug 22, 2017
@samuelkarp samuelkarp added this to the 1.14.4 milestone Aug 22, 2017
@richardpen richardpen deleted the fix-snapshot-agent branch November 21, 2017 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants