Use waitgroup to stall handler?
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler 2021-03-07 21:39:57 -05:00
parent 73ceab9418
commit 0356da8fa2
1 changed files with 8 additions and 2 deletions

10
main.go
View File

@ -109,14 +109,14 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
contentType = contentType[0:idx] contentType = contentType[0:idx]
} }
wg := &sync.WaitGroup{}
switch contentType { switch contentType {
case "multipart/form-data": case "multipart/form-data":
if r.MultipartForm == nil { if r.MultipartForm == nil {
r.ParseMultipartForm(32 << 20) r.ParseMultipartForm(32 << 20)
} }
wg := &sync.WaitGroup{}
log.WithField("contentType", contentType).Debug("Adding files from multipart form as jobs") log.WithField("contentType", contentType).Debug("Adding files from multipart form as jobs")
fileCount := 0 fileCount := 0
@ -156,6 +156,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
wg.Wait()
log.WithField("count", fileCount).Debug("Waiting for jobs to finish") log.WithField("count", fileCount).Debug("Waiting for jobs to finish")
log.WithField("matches", res).Debug("Matched rules") log.WithField("matches", res).Debug("Matched rules")
@ -164,6 +166,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
job := &Job{ job := &Job{
Data: r.Body, Data: r.Body,
Callback: func(m yara.MatchRules, err error) { Callback: func(m yara.MatchRules, err error) {
wg.Add(1)
log.WithField("match", m).Debug("Matched rules") log.WithField("match", m).Debug("Matched rules")
if err != nil { if err != nil {
@ -177,6 +181,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
log.WithField("contentType", contentType).Debug("Scanning contents of body") log.WithField("contentType", contentType).Debug("Scanning contents of body")
jobChan <- job jobChan <- job
wg.Wait()
} }
} }