Lcos-000 commented on code in PR #3623:
URL: https://github.com/apache/dubbo-go/pull/3623#discussion_r3750116665
##########
registry/servicediscovery/service_discovery_registry.go:
##########
@@ -514,11 +514,10 @@ func (s *serviceDiscoveryRegistry) Subscribe(url
*common.URL, notify registry.No
" either specify 'provided-by' for reference or enable
metadata-report center subscription url:%s", url.String())
} else {
logger.Infof("[Registry][ServiceDiscovery] find initial mapping
applications %q for service %s", services, url.ServiceKey())
- // first notify
- err :=
mappingListener.OnEvent(registry.NewServiceMappingChangedEvent(url.ServiceKey(),
services))
- if err != nil {
- logger.Errorf("[Registry][ServiceDiscovery]
ServiceInstancesChangedListenerImpl handle error, err=%v", err)
- }
+ // Subscribe the initial applications directly. The mapping
listener tracks
+ // changes after the initial subscription; routing this event
through it
+ // makes provided-by look like an unchanged mapping and skips
SubscribeURL.
+ s.SubscribeURL(url, notify, services)
Review Comment:
Thanks for the P1 and the repro — confirmed. `SubscribeURL`'s fast path
still calls `subscribeAndNotify`, which spawns `go
s.serviceDiscovery.AddListener(listener)` unconditionally, so a same-set replay
on the metadata-report path re-registers (AddListener 1->2 in your test).
Narrowed the fix in commit `ed4176d1`:
- `provided-by` path: subscribe directly via `SubscribeURL` (explicit,
unchanging target — no diff semantics apply)
- metadata-report path: keep the initial subscription on `OnEvent` so
`oldServiceNames` baseline is updated and later A->A is a no-op
Added regression coverage:
- `TestServiceDiscoveryRegistrySubscribeMetadataReportA2A`: initial
subscribe + replay identical mapping -> `AddListener` stays at 1
- `TestServiceDiscoveryRegistrySubscribeWithProvidedBy`: `AddListener` fires
exactly once, `GetInstances(test-app)` invoked
`go test ./registry/servicediscovery/` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]