From 4eb1aaae85fcaecff422fc4266ec0f7711c6d766 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 20 Sep 2019 16:25:29 +0100 Subject: [PATCH] Fix the proxy watcher --- proxy/mucp/mucp.go | 12 +++++++++++- router/handler/router.go | 2 +- router/service/service.go | 4 +++- router/service/watcher.go | 8 +++----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/proxy/mucp/mucp.go b/proxy/mucp/mucp.go index 9fccc6cc..8cd6df85 100644 --- a/proxy/mucp/mucp.go +++ b/proxy/mucp/mucp.go @@ -8,6 +8,7 @@ import ( "sort" "strings" "sync" + "time" "github.com/micro/go-micro/client" "github.com/micro/go-micro/codec" @@ -440,7 +441,16 @@ func NewProxy(opts ...options.Option) proxy.Proxy { // watch router service routes p.errChan = make(chan error, 1) - go p.watchRoutes() + + go func() { + // continuously attempt to watch routes + for { + // watch the routes + p.watchRoutes() + // in case of failure just wait a second + time.Sleep(time.Second) + } + }() return p } diff --git a/router/handler/router.go b/router/handler/router.go index 5e4bceb7..6c681742 100644 --- a/router/handler/router.go +++ b/router/handler/router.go @@ -164,7 +164,7 @@ func (r *Router) Watch(ctx context.Context, req *pb.WatchRequest, stream pb.Rout for { event, err := watcher.Next() if err == router.ErrWatcherStopped { - break + return errors.InternalServerError("go.micro.router", "watcher stopped") } if err != nil { diff --git a/router/service/service.go b/router/service/service.go index f3063546..7f521e8d 100644 --- a/router/service/service.go +++ b/router/service/service.go @@ -357,7 +357,9 @@ func (s *svc) Watch(opts ...router.WatchOption) (router.Watcher, error) { if err != nil { return nil, err } - var options router.WatchOptions + options := router.WatchOptions{ + Service: "*", + } for _, o := range opts { o(&options) } diff --git a/router/service/watcher.go b/router/service/watcher.go index f0fb3d5c..01124473 100644 --- a/router/service/watcher.go +++ b/router/service/watcher.go @@ -70,11 +70,9 @@ func (w *watcher) watch(stream pb.Router_WatchService) error { Route: route, } - for { - select { - case w.resChan <- event: - case <-w.done: - } + select { + case w.resChan <- event: + case <-w.done: } }