diff --git a/client/client.go b/client/client.go index 8815d5a76..baf463dd3 100644 --- a/client/client.go +++ b/client/client.go @@ -212,7 +212,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic allocUpdates: make(chan *structs.Allocation, 64), shutdownCh: make(chan struct{}), triggerDiscoveryCh: make(chan struct{}), - triggerNodeUpdate: make(chan struct{}), + triggerNodeUpdate: make(chan struct{}, 64), serversDiscoveredCh: make(chan struct{}), } @@ -961,7 +961,7 @@ func (c *Client) updateNodeFromFingerprint(response *cstructs.FingerprintRespons c.configLock.Lock() defer c.configLock.Unlock() - var nodeHasChanged bool + nodeHasChanged := false for name, newVal := range response.Attributes { oldVal := c.config.Node.Attributes[name] @@ -1020,6 +1020,9 @@ func resourcesAreEqual(first, second *structs.Resources) bool { if first.IOPS != second.IOPS { return false } + if len(first.Networks) != len(second.Networks) { + return false + } for i, e := range first.Networks { if len(second.Networks) < i { return false @@ -1535,22 +1538,27 @@ func (c *Client) updateNode() { // it will update the client node copy and re-register the node. func (c *Client) watchNodeUpdates() { var hasChanged bool + syncTicker := time.NewTicker(c.retryIntv(nodeUpdateRetryIntv)) + for { select { - case <-time.After(c.retryIntv(nodeUpdateRetryIntv)): - if hasChanged { - c.logger.Printf("[DEBUG] client: state changed, updating node and re-registering.") - - // Update the config copy. - c.configLock.Lock() - node := c.config.Node.Copy() - c.configCopy.Node = node - c.configLock.Unlock() - - c.retryRegisterNode() - - hasChanged = false + case <-syncTicker.C: + if !hasChanged { + continue } + c.logger.Printf("[DEBUG] client: state changed, updating node and re-registering.") + + // Update the config copy. + c.configLock.Lock() + node := c.config.Node.Copy() + c.configCopy.Node = node + c.configLock.Unlock() + + c.retryRegisterNode() + + hasChanged = false + syncTicker.Stop() + syncTicker = time.NewTicker(c.retryIntv(nodeUpdateRetryIntv)) case <-c.triggerNodeUpdate: hasChanged = true case <-c.shutdownCh: diff --git a/client/fingerprint_manager.go b/client/fingerprint_manager.go index a191555aa..713189604 100644 --- a/client/fingerprint_manager.go +++ b/client/fingerprint_manager.go @@ -104,11 +104,11 @@ func (fm *FingerprintManager) fingerprint(name string, f fingerprint.Fingerprint return false, err } - fm.nodeLock.Lock() if node := fm.updateNode(&response); node != nil { + fm.nodeLock.Lock() fm.node = node + fm.nodeLock.Unlock() } - fm.nodeLock.Unlock() return response.Detected, nil }