Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-6909 Fixed writing to the closed channel #115

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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