-
Notifications
You must be signed in to change notification settings - Fork 619
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
Conversation
@@ -96,6 +98,18 @@ func newDockerTaskEngineState() *DockerTaskEngineState { | |||
} | |||
} | |||
|
|||
// Reset resets all the states | |||
func (state *DockerTaskEngineState) Reset() { | |||
state.lock.RLock() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
0130339
to
f531ef9
Compare
@@ -96,6 +98,18 @@ func newDockerTaskEngineState() *DockerTaskEngineState { | |||
} | |||
} | |||
|
|||
// Reset resets all the states | |||
func (state *DockerTaskEngineState) Reset() { |
There was a problem hiding this comment.
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?
f531ef9
to
e24a2b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
e24a2b5
to
bd577e5
Compare
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
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes:
Description for the changelog
Licensing
This contribution is under the terms of the Apache 2.0 License:
yes