Skip to content
Permalink
Browse files

Added mutex lock to avoid race conditions on multipart file reading

  • Loading branch information...
eko committed Apr 10, 2019
1 parent c2a08e0 commit fc1b5082e93495577c32b137c38609adb1dca1a2
Showing with 5 additions and 0 deletions.
  1. +5 −0 middleware.go
@@ -34,6 +34,7 @@ var (
operations map[string]interface{}
fileChannel = make(chan fileData)
wg sync.WaitGroup
l sync.Mutex
)

// Handler is the middleware function that retrieves the incoming HTTP request and
@@ -62,6 +63,8 @@ func Handler(next http.Handler) http.Handler {
return
}

l.Lock()

r.ParseMultipartForm((1 << 20) * 64)
m := r.PostFormValue("map")
if &m == nil {
@@ -103,6 +106,8 @@ func Handler(next http.Handler) http.Handler {
}

next.ServeHTTP(w, r)

l.Unlock()
})
}

0 comments on commit fc1b508

Please sign in to comment.
You can’t perform that action at this time.