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

Agent state: do not deregister service checks twice #6168

Merged
merged 1 commit into from
Jan 17, 2020
Merged
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
20 changes: 15 additions & 5 deletions agent/local/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,12 @@ func (l *State) deleteService(key structs.ServiceID) error {
switch {
case err == nil || strings.Contains(err.Error(), "Unknown service"):
delete(l.services, key)
// service deregister also deletes associated checks
for _, c := range l.checks {
if c.Deleted && c.Check.ServiceID == key.ID {
l.pruneCheck(c.Check.CompoundCheckID())
}
}
l.logger.Printf("[INFO] agent: Deregistered service %q", key.ID)
return nil

Expand Down Expand Up @@ -1125,11 +1131,7 @@ func (l *State) deleteCheck(key structs.CheckID) error {
err := l.Delegate.RPC("Catalog.Deregister", &req, &out)
switch {
case err == nil || strings.Contains(err.Error(), "Unknown check"):
c := l.checks[key]
if c != nil && c.DeferCheck != nil {
c.DeferCheck.Stop()
}
delete(l.checks, key)
l.pruneCheck(key)
l.logger.Printf("[INFO] agent: Deregistered check %q", key.String())
return nil

Expand All @@ -1147,6 +1149,14 @@ func (l *State) deleteCheck(key structs.CheckID) error {
}
}

func (l *State) pruneCheck(id structs.CheckID) {
c := l.checks[id]
if c != nil && c.DeferCheck != nil {
c.DeferCheck.Stop()
}
delete(l.checks, id)
}

// syncService is used to sync a service to the server
func (l *State) syncService(key structs.ServiceID) error {
// If the service has associated checks that are out of sync,
Expand Down