From 4480129555971e26a9f6b86102b430959d929ea7 Mon Sep 17 00:00:00 2001 From: Dmitry Selivanov Date: Fri, 23 Jun 2023 11:13:57 +0200 Subject: [PATCH] fix: onNewDiscCallback should be called before srv existence check --- services_pool.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services_pool.go b/services_pool.go index e0f479c..4b7b0b0 100644 --- a/services_pool.go +++ b/services_pool.go @@ -157,10 +157,6 @@ func (p *ServicesPool) DiscoverServices() error { // TODO for the best scaling we need to change this part to map-based compare mechanic for _, newService := range newServices { - if p.list.IsServiceExists(newService) { - continue - } - if newService == nil { logger.Log().Warn("newService is nil during discovery") continue @@ -172,13 +168,16 @@ func (p *ServicesPool) DiscoverServices() error { continue } - p.list.Add(mutatedService) - if p.onNewDiscCallback != nil { if err := p.onNewDiscCallback(mutatedService); err != nil { logger.Log().Warn(fmt.Sprintf("callback on new discovered service: %s", err)) } } + + if p.list.IsServiceExists(newService) { + continue + } + p.list.Add(mutatedService) } return nil }