Skip to content

Commit

Permalink
Merge pull request #115 from hellofresh/hotfix/race-condition
Browse files Browse the repository at this point in the history
PT-6909 Fixed writing to the closed channel
  • Loading branch information
vgarvardt authored Apr 3, 2020
2 parents 1f12e9d + 052daa7 commit b572200
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/dumper/query/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"strconv"
"sync"
"time"

sq "github.com/Masterminds/squirrel"
Expand Down Expand Up @@ -46,6 +47,7 @@ func (d *textDumper) Dump(done chan<- struct{}, cfgTables config.Tables, concurr
return wErrors.Wrap(err, "could not write structure to output")
}

var wg sync.WaitGroup
for _, tbl := range tables {
var opts reader.ReadTableOpt
logger := log.WithField("table", tbl)
Expand All @@ -64,11 +66,13 @@ func (d *textDumper) Dump(done chan<- struct{}, cfgTables config.Tables, concurr
// Create read/write chanel
rowChan := make(chan database.Row)

wg.Add(1)
go func(tableName string) {
defer wg.Done()

for {
row, more := <-rowChan
if !more {
done <- struct{}{}
return
}

Expand All @@ -92,6 +96,11 @@ func (d *textDumper) Dump(done chan<- struct{}, cfgTables config.Tables, concurr
}
}

go func() {
wg.Wait()
done <- struct{}{}
}()

return nil
}

Expand Down

0 comments on commit b572200

Please sign in to comment.