Fix hashing of the service definition

Maps are sorted randomly, order the keys as a slice
This commit is contained in:
Shannon Wynter 2017-08-24 18:25:05 +10:00
parent e3f818d18e
commit 0e696f4907

View File

@ -3,6 +3,7 @@ package server
import (
"fmt"
"runtime/debug"
"sort"
"strconv"
"strings"
"sync"
@ -232,19 +233,34 @@ func (s *rpcServer) Register() error {
node.Metadata["registry"] = config.Registry.String()
s.RLock()
var endpoints []*registry.Endpoint
for _, e := range s.handlers {
// Maps are ordered randomly, sort the keys for consistency
var handlerList []string
for n, e := range s.handlers {
// Only advertise non internal handlers
if !e.Options().Internal {
endpoints = append(endpoints, e.Endpoints()...)
handlerList = append(handlerList, n)
}
}
for e, _ := range s.subscribers {
sort.Strings(handlerList)
var subscriberList []*subscriber
for e := range s.subscribers {
// Only advertise non internal subscribers
if !e.Options().Internal {
endpoints = append(endpoints, e.Endpoints()...)
subscriberList = append(subscriberList, e)
}
}
sort.Slice(subscriberList, func(i, j int) bool {
return subscriberList[i].topic > subscriberList[j].topic
})
var endpoints []*registry.Endpoint
for _, n := range handlerList {
endpoints = append(endpoints, s.handlers[n].Endpoints()...)
}
for _, e := range subscriberList {
endpoints = append(endpoints, e.Endpoints()...)
}
s.RUnlock()
service := &registry.Service{