From 9e74313988b43b0f2f7eb4007d6a5306e361f76f Mon Sep 17 00:00:00 2001 From: Chris Banks Date: Sat, 19 Aug 2023 23:22:07 +0100 Subject: [PATCH] Fetch the route count once, while holding the lock. Not really a problem in practice as it'd be hard to get a second reload running in between the `rt.lock.Unlock()` and the `rt.mux.RouteCount()`, but this should be slightly more robust to future changes. --- lib/router.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/router.go b/lib/router.go index 042764d0..3e720274 100644 --- a/lib/router.go +++ b/lib/router.go @@ -238,11 +238,11 @@ func (rt *Router) reloadRoutes(db *mgo.Database, currentOptime bson.MongoTimesta rt.lock.Lock() rt.mux = newmux + routeCount := rt.mux.RouteCount() rt.lock.Unlock() - logInfo(fmt.Sprintf("router: reloaded %d routes", rt.mux.RouteCount())) - - routesCountMetric.Set(float64(rt.mux.RouteCount())) + logInfo(fmt.Sprintf("router: reloaded %d routes", routeCount)) + routesCountMetric.Set(float64(routeCount)) } func (rt *Router) getCurrentMongoInstance(db mongoDatabase) (MongoReplicaSetMember, error) {