diff --git a/agent/agent.go b/agent/agent.go index 7751a2f1c..1870e477c 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -2185,7 +2185,14 @@ func (a *Agent) RemoveProxy(proxyID string, persist bool) error { } // Remove the proxy from the local state - if _, err := a.State.RemoveProxy(proxyID); err != nil { + p, err := a.State.RemoveProxy(proxyID) + if err != nil { + return err + } + + // Remove the proxy service as well. The proxy ID is also the ID + // of the servie, but we might as well use the service pointer. + if err := a.RemoveService(p.Proxy.ProxyService.ID, persist); err != nil { return err } diff --git a/agent/agent_test.go b/agent/agent_test.go index cb7c4d6fc..9a7c2a8de 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -2706,14 +2706,14 @@ func TestAgent_RemoveProxy(t *testing.T) { // Test the ID was created as we expect. gotProxy := a.State.Proxy("web-proxy") - gotProxy.Proxy.ProxyService = nil - require.Equal(pReg, gotProxy.Proxy) + require.NotNil(gotProxy) err := a.RemoveProxy("web-proxy", false) require.NoError(err) gotProxy = a.State.Proxy("web-proxy") require.Nil(gotProxy) + require.Nil(a.State.Service("web-proxy"), "web-proxy service") // Removing invalid proxy should be an error err = a.RemoveProxy("foobar", false)