Skip to content

Commit

Permalink
static file map race bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
JessonChan committed Mar 4, 2016
1 parent 4b99e41 commit 226e54e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion staticfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ type serveContentHolder struct {

var (
staticFileMap = make(map[string]*serveContentHolder)
mapLock sync.Mutex
mapLock sync.RWMutex
)

func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, string, *serveContentHolder, error) {
mapKey := acceptEncoding + ":" + filePath
mapLock.RLock()
mapFile, _ := staticFileMap[mapKey]
mapLock.RUnlock()
if isOk(mapFile, fi) {
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
}
Expand Down

0 comments on commit 226e54e

Please sign in to comment.