diff --git a/home/clients.go b/home/clients.go index b5ca3d2d..3b94edef 100644 --- a/home/clients.go +++ b/home/clients.go @@ -468,12 +468,16 @@ func (clients *clientsContainer) Update(name string, c Client) error { // update Name index if old.Name != c.Name { + delete(clients.list, old.Name) clients.list[c.Name] = old } // update upstreams cache - delete(clients.upstreamsCache, name) - delete(clients.upstreamsCache, old.Name) + if old.Name != c.Name { + delete(clients.upstreamsCache, old.Name) + } else { + delete(clients.upstreamsCache, c.Name) + } *old = c return nil diff --git a/home/clients_test.go b/home/clients_test.go index 490035ed..e227d699 100644 --- a/home/clients_test.go +++ b/home/clients_test.go @@ -114,6 +114,7 @@ func TestClients(t *testing.T) { c = Client{} c, b = clients.Find("1.1.1.2") assert.True(t, b && c.Name == "client1-renamed" && c.IDs[0] == "1.1.1.2" && c.UseOwnSettings) + assert.True(t, clients.list["client1"] == nil) // failed remove - no such name if clients.Del("client3") {