From a5128da67aff6ea971b795c8c34f5de7148a9dd7 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Fri, 11 Sep 2015 08:34:52 -0700 Subject: [PATCH] markdown: fix race in accessing map Signed-off-by: Alexander Morozov --- middleware/markdown/markdown.go | 5 ++++- middleware/markdown/process.go | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/middleware/markdown/markdown.go b/middleware/markdown/markdown.go index 2b7fe072..bdf142cf 100644 --- a/middleware/markdown/markdown.go +++ b/middleware/markdown/markdown.go @@ -126,8 +126,11 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error } } + cfg.RLock() + filepath, ok := cfg.StaticFiles[fpath] + cfg.RUnlock() // if static site is generated, attempt to use it - if filepath, ok := cfg.StaticFiles[fpath]; ok { + if ok { if fs1, err := os.Stat(filepath); err == nil { // if markdown has not been modified since static page // generation, serve the static page diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index 70947854..b7f64404 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -153,7 +153,9 @@ func (md Markdown) generatePage(c *Config, requestPath string, content []byte) e return err } + c.Lock() c.StaticFiles[requestPath] = filePath + c.Unlock() } return nil