From 226e54e0d8d81b287a67949d9559572be5ccc363 Mon Sep 17 00:00:00 2001 From: JessonChan Date: Fri, 4 Mar 2016 10:15:59 +0800 Subject: [PATCH] static file map race bug fixed --- staticfile.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/staticfile.go b/staticfile.go index 9534ce91..0aad2c81 100644 --- a/staticfile.go +++ b/staticfile.go @@ -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 }