From 49a8d05e461b2d9b609de96d453923e0d3ef42e5 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 11 Aug 2020 16:57:04 +0100 Subject: [PATCH] router/registry: fix expiring routes bug (#1927) --- registry.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/registry.go b/registry.go index 113e249..11571a1 100644 --- a/registry.go +++ b/registry.go @@ -205,7 +205,14 @@ func (r *rtr) loadRoutes(reg registry.Registry) error { if len(routes) > 0 { logger.Tracef("Creating routes for service %v domain: %v", service, domain) for _, rt := range routes { - if err := r.table.Create(rt); err != nil { + err := r.table.Create(rt) + + // update the route to prevent it from expiring + if err == router.ErrDuplicateRoute { + err = r.table.Update(rt) + } + + if err != nil { logger.Errorf("Error creating route for service %v in domain %v: %v", service, domain, err) } } @@ -228,7 +235,14 @@ func (r *rtr) loadRoutes(reg registry.Registry) error { if len(routes) > 0 { logger.Tracef("Creating routes for service %v domain: %v", srv, domain) for _, rt := range routes { - if err := r.table.Create(rt); err != nil { + err := r.table.Create(rt) + + // update the route to prevent it from expiring + if err == router.ErrDuplicateRoute { + err = r.table.Update(rt) + } + + if err != nil { logger.Errorf("Error creating route for service %v in domain %v: %v", service, domain, err) } }