From 473b26f877fd233f6ed5700964d4c4f0465d93d8 Mon Sep 17 00:00:00 2001 From: alanxtl Date: Tue, 2 Jun 2026 13:19:52 +0800 Subject: [PATCH 1/2] stablize_register_services --- .../service_discovery_registry.go | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go index 6d07dd318e..2158f9b287 100644 --- a/registry/servicediscovery/service_discovery_registry.go +++ b/registry/servicediscovery/service_discovery_registry.go @@ -19,20 +19,15 @@ package servicediscovery import ( "errors" + "sort" "strconv" "strings" "sync" "time" -) -import ( gxset "github.com/dubbogo/gost/container/set" "github.com/dubbogo/gost/log/logger" - perrors "github.com/pkg/errors" -) - -import ( "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/common/extension" @@ -41,9 +36,13 @@ import ( "dubbo.apache.org/dubbo-go/v3/metadata/mapping" "dubbo.apache.org/dubbo-go/v3/metadata/report" "dubbo.apache.org/dubbo-go/v3/metrics" + perrors "github.com/pkg/errors" + metricsMetadata "dubbo.apache.org/dubbo-go/v3/metrics/metadata" + metricsRegistry "dubbo.apache.org/dubbo-go/v3/metrics/registry" "dubbo.apache.org/dubbo-go/v3/registry" + _ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery/customizer" ) @@ -194,8 +193,7 @@ func (s *serviceDiscoveryRegistry) UnSubscribe(url *common.URL, listener registr if services == nil { return nil } - // FIXME ServiceNames.String() is not good - serviceNamesKey := services.String() + serviceNamesKey := sortServices(services) l := s.serviceListeners[serviceNamesKey] if l != nil { l.RemoveListener(url.ServiceKey()) @@ -350,9 +348,8 @@ func (s *serviceDiscoveryRegistry) Subscribe(url *common.URL, notify registry.No } func (s *serviceDiscoveryRegistry) SubscribeURL(url *common.URL, notify registry.NotifyListener, services *gxset.HashSet) { - // FIXME ServiceNames.String() is not good var err error - serviceNamesKey := services.String() + serviceNamesKey := sortServices(services) protocol := constant.TriProtocol // consume "tri" protocol by default, other protocols need to be specified on reference/consumer explicitly if url.Protocol != "" { protocol = url.Protocol @@ -392,6 +389,17 @@ func (s *serviceDiscoveryRegistry) SubscribeURL(url *common.URL, notify registry }() } +func sortServices(services *gxset.HashSet) string { + list := make([]string, 0, services.Size()) + for _, v := range services.Values() { + if s, ok := v.(string); ok && s != "" { + list = append(list, s) + } + } + sort.Strings(list) + return strings.Join(list, ",") +} + // LoadSubscribeInstances load subscribe instance func (s *serviceDiscoveryRegistry) LoadSubscribeInstances(url *common.URL, notify registry.NotifyListener) error { return nil From 0aa91ec6dbb85589443a5fb731fccacf5857243b Mon Sep 17 00:00:00 2001 From: alanxtl Date: Tue, 2 Jun 2026 13:31:56 +0800 Subject: [PATCH 2/2] imprt format --- .../servicediscovery/service_discovery_registry.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go index 2158f9b287..45562c55bc 100644 --- a/registry/servicediscovery/service_discovery_registry.go +++ b/registry/servicediscovery/service_discovery_registry.go @@ -24,10 +24,16 @@ import ( "strings" "sync" "time" +) +import ( gxset "github.com/dubbogo/gost/container/set" "github.com/dubbogo/gost/log/logger" + perrors "github.com/pkg/errors" +) + +import ( "dubbo.apache.org/dubbo-go/v3/common" "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/common/extension" @@ -36,13 +42,9 @@ import ( "dubbo.apache.org/dubbo-go/v3/metadata/mapping" "dubbo.apache.org/dubbo-go/v3/metadata/report" "dubbo.apache.org/dubbo-go/v3/metrics" - perrors "github.com/pkg/errors" - metricsMetadata "dubbo.apache.org/dubbo-go/v3/metrics/metadata" - metricsRegistry "dubbo.apache.org/dubbo-go/v3/metrics/registry" "dubbo.apache.org/dubbo-go/v3/registry" - _ "dubbo.apache.org/dubbo-go/v3/registry/servicediscovery/customizer" )