Skip to content

Commit

Permalink
fix(router): panic caused by concurrent map read and write (v2fly#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
KujouRinka committed Aug 31, 2023
1 parent 88b5b55 commit 6b65213
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/router/weight.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"regexp"
"strconv"
"strings"
"sync"
)

type weightScaler func(value, weight float64) float64
Expand All @@ -26,10 +27,13 @@ type WeightManager struct {
cache map[string]float64
scaler weightScaler
defaultWeight float64
mu sync.Mutex
}

// Get gets the weight of specified tag
func (s *WeightManager) Get(tag string) float64 {
s.mu.Lock()
defer s.mu.Unlock()
weight, ok := s.cache[tag]
if ok {
return weight
Expand Down

0 comments on commit 6b65213

Please sign in to comment.