Fix hashing of the service definition
Maps are sorted randomly, order the keys as a slice
This commit is contained in:
parent
e3f818d18e
commit
0e696f4907
@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -232,19 +233,34 @@ func (s *rpcServer) Register() error {
|
|||||||
node.Metadata["registry"] = config.Registry.String()
|
node.Metadata["registry"] = config.Registry.String()
|
||||||
|
|
||||||
s.RLock()
|
s.RLock()
|
||||||
var endpoints []*registry.Endpoint
|
// Maps are ordered randomly, sort the keys for consistency
|
||||||
for _, e := range s.handlers {
|
var handlerList []string
|
||||||
|
for n, e := range s.handlers {
|
||||||
// Only advertise non internal handlers
|
// Only advertise non internal handlers
|
||||||
if !e.Options().Internal {
|
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
|
// Only advertise non internal subscribers
|
||||||
if !e.Options().Internal {
|
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()
|
s.RUnlock()
|
||||||
|
|
||||||
service := ®istry.Service{
|
service := ®istry.Service{
|
||||||
|
Loading…
Reference in New Issue
Block a user