diff --git a/node/node.go b/node/node.go index 036542a02c9f1c4ee0e6f3ff41dbef8a0d76fc22..dc5622859597ace3330bc93f8a32170d39955a1c 100644 --- a/node/node.go +++ b/node/node.go @@ -83,11 +83,16 @@ func (c *clusterConfig) setMountIfChanged(m *autoradio.Mount) bool { return true } -// Delete a mount (in-memory only). -func (c *clusterConfig) delMount(name string) { +// Delete a mount (in-memory only). Returns true if the mount existed +// in our configuration and was deleted successfully. +func (c *clusterConfig) delMount(name string) bool { c.lock.Lock() defer c.lock.Unlock() - delete(c.mounts, name) + if _, ok := c.mounts[name]; ok { + delete(c.mounts, name) + return true + } + return false } // Keeps the in-memory service configuration in sync with the etcd @@ -163,7 +168,11 @@ func (w *configWatcher) watcher(index uint64, stop chan bool) { case "delete": mountName := keyToMount(resp.Node.Key) log.Printf("deleted mount %s", mountName) - w.config.delMount(mountName) + if !w.config.delMount(mountName) { + // Do not trigger an update if the + // operation had no effect. + continue + } case "set", "create", "update": if !w.updateMount(resp.Node.Key, resp.Node.Value, index) { // Do not trigger an update if the