Skip to content

Commit

Permalink
Merge pull request #78 from pingcap/siddontang/fix-driver-panic
Browse files Browse the repository at this point in the history
fix driver panic
  • Loading branch information
shenli committed Sep 9, 2015
2 parents 5e8f71a + 0cb3800 commit 229f8ed
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ type driverRows struct {
rs rset.Recordset
done chan int
rows chan interface{}
wg sync.WaitGroup
}

func newEmptyDriverRows() *driverRows {
Expand All @@ -363,7 +364,13 @@ func newdriverRows(rs rset.Recordset) *driverRows {
done: make(chan int),
rows: make(chan interface{}, 500),
}
r.wg.Add(1)
go func() {
// TODO: We may change the whole implementation later, so here just using WaitGroup
// to solve issue https://github.com/pingcap/tidb/issues/57
// But if we forget close rows and do commit later, we may still meet this panic
// with very little probability.
defer r.wg.Done()
err := io.EOF
if e := r.rs.Do(func(data []interface{}) (bool, error) {
vv, cloneErr := types.Clone(data)
Expand Down Expand Up @@ -406,6 +413,7 @@ func (r *driverRows) Columns() []string {
// Close closes the rows iterator.
func (r *driverRows) Close() error {
close(r.done)
r.wg.Wait()
return nil
}

Expand Down

0 comments on commit 229f8ed

Please sign in to comment.