From 7e5045674c6b44fe5bb1ff04fa0d644bd4e0fbce Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 9 Sep 2015 09:25:11 +0800 Subject: [PATCH 1/3] tidb: try to fix the panic #57 --- driver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/driver.go b/driver.go index b32fc5f81b..55f907579c 100644 --- a/driver.go +++ b/driver.go @@ -347,6 +347,7 @@ type driverRows struct { rs rset.Recordset done chan int rows chan interface{} + wg sync.WaitGroup } func newEmptyDriverRows() *driverRows { @@ -363,7 +364,9 @@ func newdriverRows(rs rset.Recordset) *driverRows { done: make(chan int), rows: make(chan interface{}, 500), } + r.wg.Add(1) go func() { + defer r.wg.Done() err := io.EOF if e := r.rs.Do(func(data []interface{}) (bool, error) { vv, cloneErr := types.Clone(data) @@ -406,6 +409,7 @@ func (r *driverRows) Columns() []string { // Close closes the rows iterator. func (r *driverRows) Close() error { close(r.done) + r.wg.Wait() return nil } From 533e26357b7c4eb52beb26cc74eecd1ca9bf59ea Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 9 Sep 2015 12:01:12 +0800 Subject: [PATCH 2/3] tidb: add comment --- driver.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/driver.go b/driver.go index 55f907579c..3afa1fc07e 100644 --- a/driver.go +++ b/driver.go @@ -366,6 +366,10 @@ func newdriverRows(rs rset.Recordset) *driverRows { } r.wg.Add(1) go func() { + // 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) { From 0cb3800178fee733635613f52eda672bf0834535 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 9 Sep 2015 12:24:16 +0800 Subject: [PATCH 3/3] Address comment --- driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver.go b/driver.go index 3afa1fc07e..b41c784a9b 100644 --- a/driver.go +++ b/driver.go @@ -366,7 +366,7 @@ func newdriverRows(rs rset.Recordset) *driverRows { } r.wg.Add(1) go func() { - // We may change the whole implementation later, so here just using WaitGroup + // 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.