Merge pull request #637 from github/errorwait

Resolve race condition in transfer queue error collection
This commit is contained in:
Scott Barron 2015-09-04 11:34:01 -04:00
commit 10dbfb5da8

@ -34,6 +34,7 @@ type TransferQueue struct {
transferc chan Transferable // Channel for processing transfers transferc chan Transferable // Channel for processing transfers
errorc chan error // Channel for processing errors errorc chan error // Channel for processing errors
watchers []chan string watchers []chan string
errorwait sync.WaitGroup
wait sync.WaitGroup wait sync.WaitGroup
} }
@ -48,6 +49,8 @@ func newTransferQueue(files int, size int64, dryRun bool) *TransferQueue {
transferables: make(map[string]Transferable), transferables: make(map[string]Transferable),
} }
q.errorwait.Add(1)
q.run() q.run()
return q return q
@ -82,6 +85,7 @@ func (q *TransferQueue) Wait() {
} }
q.meter.Finish() q.meter.Finish()
q.errorwait.Wait()
} }
// Watch returns a channel where the queue will write the OID of each transfer // Watch returns a channel where the queue will write the OID of each transfer
@ -216,6 +220,7 @@ func (q *TransferQueue) errorCollector() {
for err := range q.errorc { for err := range q.errorc {
q.errors = append(q.errors, err) q.errors = append(q.errors, err)
} }
q.errorwait.Done()
} }
func (q *TransferQueue) transferWorker() { func (q *TransferQueue) transferWorker() {