Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit bdd663a

Browse files
authored
Merge pull request #626 from kuba--/fix-625/panic
recover panic for partitions
2 parents 19a4cbb + 7fde86d commit bdd663a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

sql/plan/exchange.go

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ func (it *exchangeRowIter) start() {
178178

179179
func (it *exchangeRowIter) iterPartitions(ch chan<- sql.Partition) {
180180
defer func() {
181+
if x := recover(); x != nil {
182+
it.err <- fmt.Errorf("mysql_server caught panic:\n%v", x)
183+
}
184+
181185
close(ch)
182186

183187
if err := it.partitions.Close(); err != nil {

sql/plan/exchange_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ func TestExchangeCancelled(t *testing.T) {
9090
require.Equal(context.Canceled, err)
9191
}
9292

93+
func TestExchangePanicRecover(t *testing.T) {
94+
ctx := sql.NewContext(context.Background())
95+
it := &partitionPanic{}
96+
ex := newExchangeRowIter(ctx, 1, it, nil)
97+
ex.start()
98+
99+
require.True(t, it.closed)
100+
}
101+
93102
type partitionable struct {
94103
sql.Node
95104
partitions int
@@ -165,3 +174,18 @@ func (r *partitionRows) Close() error {
165174
r.num = -1
166175
return nil
167176
}
177+
178+
type partitionPanic struct {
179+
sql.Partition
180+
closed bool
181+
}
182+
183+
func (*partitionPanic) Next() (sql.Partition, error) {
184+
panic("partitionPanic.Next")
185+
return nil, nil
186+
}
187+
188+
func (p *partitionPanic) Close() error {
189+
p.closed = true
190+
return nil
191+
}

0 commit comments

Comments
 (0)