Skip to content
This repository was archived by the owner on Dec 22, 2025. It is now read-only.

Commit b572200

Browse files
authored
Merge pull request #115 from hellofresh/hotfix/race-condition
PT-6909 Fixed writing to the closed channel
2 parents 1f12e9d + 052daa7 commit b572200

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/dumper/query/dumper.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"strconv"
7+
"sync"
78
"time"
89

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

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

69+
wg.Add(1)
6770
go func(tableName string) {
71+
defer wg.Done()
72+
6873
for {
6974
row, more := <-rowChan
7075
if !more {
71-
done <- struct{}{}
7276
return
7377
}
7478

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

99+
go func() {
100+
wg.Wait()
101+
done <- struct{}{}
102+
}()
103+
95104
return nil
96105
}
97106

0 commit comments

Comments
 (0)