From b241cfc7fdae471bfff04801617a90b02c88f7c9 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 15:18:00 -0800 Subject: [PATCH] Whoops. Return an empty set in the event that there are multiple matches. --- consul/state/catalog.go | 42 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/consul/state/catalog.go b/consul/state/catalog.go index aa1c98db7..c0212c05a 100644 --- a/consul/state/catalog.go +++ b/consul/state/catalog.go @@ -694,26 +694,34 @@ func (s *StateStore) NodeServices(ws memdb.WatchSet, nodeNameOrID string) (uint6 return 0, nil, fmt.Errorf("node lookup failed: %s", err) } - if n == nil { - if len(nodeNameOrID) >= minUUIDLookupLen { - // Attempt to lookup the node by it's node ID - var idWatchCh <-chan struct{} - idWatchCh, n, err = tx.FirstWatch("nodes", "uuid_prefix", nodeNameOrID) - if err != nil { - return 0, nil, fmt.Errorf("node ID lookup failed: %s", err) - } - if n == nil { - ws.Add(watchCh) - return 0, nil, nil - } else { - ws.Add(idWatchCh) - } - } else { + if n != nil { + ws.Add(watchCh) + } else { + if len(nodeNameOrID) < minUUIDLookupLen { ws.Add(watchCh) return 0, nil, nil } - } else { - ws.Add(watchCh) + + // Attempt to lookup the node by it's node ID + iter, err := tx.Get("nodes", "uuid_prefix", nodeNameOrID) + if err != nil { + return 0, nil, fmt.Errorf("node ID lookup failed: %s", err) + } + n = iter.Next() + if n == nil { + ws.Add(watchCh) + return 0, nil, nil + } + + idWatchCh := iter.WatchCh() + if iter.Next() != nil { + // Watch on the channel that did a node name lookup if we don't find + // anything when searching by Node ID. + ws.Add(watchCh) + return 0, nil, nil + } + + ws.Add(idWatchCh) } node := n.(*structs.Node)