Skip to content

Commit

Permalink
go-patricia is not thread safe so we have to lock around it
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Jan 14, 2016
1 parent e3d759b commit 4775340
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/location_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"regexp"
"strings"
"sync"

"github.com/ironsmile/nedomi/types"
"github.com/tchap/go-patricia/patricia"
Expand All @@ -24,6 +25,7 @@ var errExactMatch = fmt.Errorf("exact match") // not an actual error

// LocationMuxer is muxer for Location types. Given a slice of them it can tell which one should respond to a given path.
type LocationMuxer struct {
sync.Mutex
regexes []*regexLocation
locationTrie *patricia.Trie
}
Expand Down Expand Up @@ -120,6 +122,8 @@ func (lm *LocationMuxer) firstMatchingRegex(path string) *types.Location {

// Match returns the Location which should respond to the given path
func (lm *LocationMuxer) Match(path string) *types.Location {
lm.Lock()
defer lm.Unlock()
location := lm.longestMatchingPath(path)
if location != nil && isLocationType(location, bestNonRegular) {
return location
Expand Down

0 comments on commit 4775340

Please sign in to comment.