-
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
*: fix many leaks of the test case #26909
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
@@ -298,14 +300,17 @@ func (e *HashAggExec) Close() error { | |||
|
|||
// Open implements the Executor Open interface. | |||
func (e *HashAggExec) Open(ctx context.Context) error { | |||
if err := e.baseExecutor.Open(ctx); err != nil { | |||
return err | |||
} | |||
failpoint.Inject("mockHashAggExecBaseExecutorOpenReturnedError", func(val failpoint.Value) { |
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.
The failpoint is moved before the Open
, because after calling Open
and then error, the children Executor is not closed.
return err | ||
} | ||
// If panic in Open, the children executor should be closed because they are open. | ||
defer closeBaseExecutor(&e.baseExecutor) |
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.
For the panic in Open
case, we do not handle the resource release well.
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.
Actually here is not just a problem in the test code, it's also a bug of the product.
set @@tidb_memtracker_size = xxx;
insert into select * from t1 where a in select b from t2 ...
// If Out of memory, panic in Open, then there will be goroutine leak
@@ -44,6 +44,10 @@ func (e *ExplainExec) Open(ctx context.Context) error { | |||
// Close implements the Executor Close interface. | |||
func (e *ExplainExec) Close() error { | |||
e.rows = nil | |||
if e.analyzeExec != nil && !e.executed { | |||
// Open(), but Next() is not called. | |||
return e.analyzeExec.Close() |
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.
Some test code run the following logic:
rs, err := Execute("explan analyze xxxxx")
// Next() is not called
rs.Close()
And the analyzeExec
is not released ...
Fix for it.
@@ -57,16 +57,22 @@ func (s *seqTestSuite) TestPrepared(c *C) { | |||
tk.MustExec("create table prepare_test (id int PRIMARY KEY AUTO_INCREMENT, c1 int, c2 int, c3 int default 1)") | |||
tk.MustExec("insert prepare_test (c1) values (1),(2),(NULL)") | |||
|
|||
tk.MustExec(`prepare stmt_test_1 from 'select id from prepare_test where id > ?'; set @a = 1; execute stmt_test_1 using @a;`) | |||
tk.MustExec(`prepare stmt_test_1 from 'select id from prepare_test where id > ?';`) |
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.
Multiple statement is ban in the real code.
Some test code are still using them ... and the resulted record set seems not to be closed correctly.
@@ -1378,9 +1378,6 @@ func upgradeToVer67(s Session, ver int64) { | |||
if err != nil { | |||
logutil.BgLogger().Fatal("upgradeToVer67 error", zap.Error(err)) | |||
} | |||
if rs != nil { | |||
defer terror.Call(rs.Close) |
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.
The defer close the result too late, do it explicitly.
func() {
t1, err := Execute("sql1 ...")
defer t1.Close()
t2, err := Execute("sql2" ...)
// t1 is not closed, so statement context is still in use
// and we will have trouble reuse the statement context.
}
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.
I remembered that recordset.Close()
has an error returned, do we assert it? I will give lgtm, if you don't want to do it now.
In the test case many places ignore the error. golint does not check the ignored error in the test code currently. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 947f271
|
@tiancaiamao: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Problem Summary:
When I tried to figure out the DATA RACE in #26241, I found those problems.
The PR #26241 does not introduce the DATA RACE itself, but as it reuse statement context, if some goroutine still reference the old statement context, then the DATA RACE happen.
It help us find those leaks, typically such case:
What is changed and how it works?
What's Changed:
Fix some leak places.
How it Works:
Release resource to avoid leak
Check List
Tests
Most of the change is the test code.
Side effects
Documentation
Release note