From 88d438341051dd8e6d3025c6092670afd9a3530a Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Fri, 15 Mar 2019 21:14:46 +0100 Subject: [PATCH] Ensure we remove Connect proxy before deregistering the service itself (#5482) This will fix https://github.com/hashicorp/consul/issues/5351 --- agent/agent.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 23ce44258b..aa9de46bb4 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2075,6 +2075,17 @@ func (a *Agent) removeServiceLocked(serviceID string, persist bool) error { checkIDs = append(checkIDs, id) } + // Remove the associated managed proxy if it exists + // This has to be DONE before purging configuration as might might have issues + // With ACLs otherwise + for proxyID, p := range a.State.Proxies() { + if p.Proxy.TargetServiceID == serviceID { + if err := a.removeProxyLocked(proxyID, true); err != nil { + return err + } + } + } + // Remove service immediately if err := a.State.RemoveServiceWithChecks(serviceID, checkIDs); err != nil { a.logger.Printf("[WARN] agent: Failed to deregister service %q: %s", serviceID, err) @@ -2098,15 +2109,6 @@ func (a *Agent) removeServiceLocked(serviceID string, persist bool) error { } } - // Remove the associated managed proxy if it exists - for proxyID, p := range a.State.Proxies() { - if p.Proxy.TargetServiceID == serviceID { - if err := a.removeProxyLocked(proxyID, true); err != nil { - return err - } - } - } - a.logger.Printf("[DEBUG] agent: removed service %q", serviceID) // If any Sidecar services exist for the removed service ID, remove them too.