Skip to content

Commit

Permalink
Fetch the route count once, while holding the lock.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sengi committed Aug 19, 2023
1 parent 9f6543e commit 9e74313
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9e74313

Please sign in to comment.