Skip to content

Commit

Permalink
fix read worker sleep preventing spooler shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
arnecls committed Apr 16, 2019
1 parent 2f190cf commit b1e344e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions producer/spoolfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ func (spool *spoolFile) waitForReader() {

func (spool *spoolFile) read() {
spool.prod.AddWorker()
spool.readWorker.Add(1)
defer spool.prod.WorkerDone()

spool.readWorker.Add(1)
defer spool.readWorker.Done()

nextFile:
Expand All @@ -210,6 +211,7 @@ nextFile:
}

spool.prod.WorkerDone() // to avoid being stuck during shutdown
spool.readWorker.Done()

retry := time.After(spool.prod.maxFileAge / 2)
select {
Expand All @@ -218,14 +220,13 @@ nextFile:
}

spool.prod.AddWorker() // worker done is always called at exit
continue // ### continue, try again ###
spool.readWorker.Add(1)
continue // ### continue, try again ###
}

// Only spool back if target is not busy
for !spool.prod.IsStopping() && spool.source != nil && spool.source.IsBlocked() {
time.Sleep(time.Millisecond * 100)
println("sleep")
// ### continue, busy source ###
}

if spool.prod.IsStopping() {
Expand Down

0 comments on commit b1e344e

Please sign in to comment.