Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added mutex lock to avoid race conditions on multipart file reading
  • Loading branch information
eko committed Apr 10, 2019
1 parent c2a08e0 commit fc1b508
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions middleware.go
Expand Up @@ -34,6 +34,7 @@ var (
operations map[string]interface{} operations map[string]interface{}
fileChannel = make(chan fileData) fileChannel = make(chan fileData)
wg sync.WaitGroup wg sync.WaitGroup
l sync.Mutex
) )


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


l.Lock()

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


next.ServeHTTP(w, r) next.ServeHTTP(w, r)

l.Unlock()
}) })
} }


Expand Down

0 comments on commit fc1b508

Please sign in to comment.