-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
executor: avoid ProjectoinExec
's goroutine leak
#14127
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ccf27d0
avoid goroutine leak
fzhedu 82d34b2
add failpoint test for project
fzhedu 3c234ea
add unit test for explain
fzhedu 0128632
format including fils
fzhedu 2ff11d3
handle panic error
fzhedu ad31a60
format code
fzhedu c2d17ac
add panic test
fzhedu d090ccc
update panic test
fzhedu 488d7e1
update error
fzhedu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/pingcap/parser/mysql" | ||
"github.com/pingcap/tidb/expression" | ||
"github.com/pingcap/tidb/sessionctx/variable" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/util/chunk" | ||
"github.com/pingcap/tidb/util/mock" | ||
) | ||
|
||
var ( | ||
_ Executor = &mockErrorOperator{} | ||
) | ||
|
||
type mockErrorOperator struct { | ||
baseExecutor | ||
toPanic bool | ||
closed bool | ||
} | ||
|
||
func (e *mockErrorOperator) Open(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
func (e *mockErrorOperator) Next(ctx context.Context, req *chunk.Chunk) error { | ||
if e.toPanic { | ||
panic("next panic") | ||
} else { | ||
return errors.New("next error") | ||
} | ||
} | ||
|
||
func (e *mockErrorOperator) Close() error { | ||
e.closed = true | ||
return errors.New("close error") | ||
} | ||
|
||
func getColumns() []*expression.Column { | ||
return []*expression.Column{ | ||
{Index: 1, RetType: types.NewFieldType(mysql.TypeLonglong)}, | ||
} | ||
} | ||
|
||
// close() must be called after next() to avoid goroutines leak | ||
func TestExplainAnalyzeInvokeNextAndClose(t *testing.T) { | ||
ctx := mock.NewContext() | ||
ctx.GetSessionVars().InitChunkSize = variable.DefInitChunkSize | ||
ctx.GetSessionVars().MaxChunkSize = variable.DefMaxChunkSize | ||
schema := expression.NewSchema(getColumns()...) | ||
baseExec := newBaseExecutor(ctx, schema, nil) | ||
explainExec := &ExplainExec{ | ||
baseExecutor: baseExec, | ||
explain: nil, | ||
} | ||
// mockErrorOperator returns errors | ||
mockOper := mockErrorOperator{baseExec, false, false} | ||
explainExec.analyzeExec = &mockOper | ||
tmpCtx := context.Background() | ||
_, err := explainExec.generateExplainInfo(tmpCtx) | ||
|
||
expectedStr := "next error, close error" | ||
if err.Error() != expectedStr || !mockOper.closed { | ||
t.Errorf(err.Error()) | ||
} | ||
// mockErrorOperator panic | ||
mockOper = mockErrorOperator{baseExec, true, false} | ||
explainExec.analyzeExec = &mockOper | ||
defer func() { | ||
if panicErr := recover(); panicErr == nil || !mockOper.closed { | ||
t.Errorf("panic test failed: without panic or close() is not called") | ||
} | ||
}() | ||
_, err = explainExec.generateExplainInfo(tmpCtx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call
recover
here, the panic will be recovered here, which is not we want.Suggest just check
closed
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if without recover, the goroutine will panic, and test will not work.