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

recover panic for partitions #626

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions sql/plan/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (it *exchangeRowIter) start() {

func (it *exchangeRowIter) iterPartitions(ch chan<- sql.Partition) {
defer func() {
if x := recover(); x != nil {
it.err <- fmt.Errorf("mysql_server caught panic:\n%v", x)
}

close(ch)

if err := it.partitions.Close(); err != nil {
Expand Down
24 changes: 24 additions & 0 deletions sql/plan/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ func TestExchangeCancelled(t *testing.T) {
require.Equal(context.Canceled, err)
}

func TestExchangePanicRecover(t *testing.T) {
ctx := sql.NewContext(context.Background())
it := &partitionPanic{}
ex := newExchangeRowIter(ctx, 1, it, nil)
ex.start()

require.True(t, it.closed)
}

type partitionable struct {
sql.Node
partitions int
Expand Down Expand Up @@ -165,3 +174,18 @@ func (r *partitionRows) Close() error {
r.num = -1
return nil
}

type partitionPanic struct {
sql.Partition
closed bool
}

func (*partitionPanic) Next() (sql.Partition, error) {
panic("partitionPanic.Next")
return nil, nil
}

func (p *partitionPanic) Close() error {
p.closed = true
return nil
}