From f0c0f3d4c45f49ec8586051a1bd9e1794e523fed Mon Sep 17 00:00:00 2001 From: Patrik Lindahl Date: Tue, 19 May 2020 19:11:26 +0800 Subject: [PATCH] Fixes for #1560 (#1644) close #1560 This fixes one of the reported data races and also allows for having a different name on the micro.Service and web.Service. This makes it possible to discover the two service variants separately. Co-authored-by: Vasiliy Tolstov --- web/service.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/service.go b/web/service.go index c9efc25a..aed52eda 100644 --- a/web/service.go +++ b/web/service.go @@ -112,8 +112,8 @@ func (s *service) run(exit chan bool) { } func (s *service) register() error { - s.RLock() - defer s.RUnlock() + s.Lock() + defer s.Unlock() if s.srv == nil { return nil @@ -142,8 +142,8 @@ func (s *service) register() error { } func (s *service) deregister() error { - s.RLock() - defer s.RUnlock() + s.Lock() + defer s.Unlock() if s.srv == nil { return nil @@ -406,7 +406,9 @@ func (s *service) Init(opts ...Option) error { s.RLock() // pass in own name and version - serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) + if s.opts.Service.Name() == "" { + serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) + } serviceOpts = append(serviceOpts, micro.Version(s.opts.Version)) s.RUnlock()