Skip to content

Commit

Permalink
Fix lock in the managed routing table
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Aug 23, 2019
1 parent b3ef07d commit c5c10e0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/router/managed_routing_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ func (rt *managedRoutingTable) AddRule(rule routing.Rule) (routing.RouteID, erro
}

func (rt *managedRoutingTable) Rule(routeID routing.RouteID) (routing.Rule, error) {
rt.mu.Lock()
defer rt.mu.Unlock()

rule, err := rt.Table.Rule(routeID)
if err != nil {
return nil, err
}

rt.mu.Lock()
defer rt.mu.Unlock()
if rt.ruleIsTimedOut(routeID, rule) {
return nil, ErrRuleTimedOut
}
Expand All @@ -59,14 +60,14 @@ func (rt *managedRoutingTable) Rule(routeID routing.RouteID) (routing.Rule, erro
func (rt *managedRoutingTable) Cleanup() error {
expiredIDs := make([]routing.RouteID, 0)
rt.mu.Lock()
defer rt.mu.Unlock()

err := rt.RangeRules(func(routeID routing.RouteID, rule routing.Rule) bool {
if rt.ruleIsTimedOut(routeID, rule) {
expiredIDs = append(expiredIDs, routeID)
}
return true
})
rt.mu.Unlock()

if err != nil {
return err
}
Expand Down

0 comments on commit c5c10e0

Please sign in to comment.