-
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
exeuctor: fix coprocessor goroutine leak for IndexMerge #41610
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1ea5bf
exeuctor: make sure SelectResult.Close() is called for IndexMerge
guo-shaoge 2f1ff22
refine comments
guo-shaoge d608f4d
add case
guo-shaoge 3a86ab3
refine comment
guo-shaoge 1200adb
fix unit-test
guo-shaoge 15ed8cd
fix case build
guo-shaoge 2923852
fix sleep second
guo-shaoge 5634231
remove slice
guo-shaoge a8445b7
fix
guo-shaoge 94066e4
fix build
guo-shaoge 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,13 @@ func (e *IndexMergeReaderExecutor) startPartialIndexWorker(ctx context.Context, | |
SetFromInfoSchema(e.ctx.GetInfoSchema()). | ||
SetClosestReplicaReadAdjuster(newClosestReadAdjuster(e.ctx, &builder.Request, e.partialNetDataSizes[workID])) | ||
|
||
selectResults := make([]distsql.SelectResult, 0, len(keyRanges)) | ||
defer func() { | ||
// To make sure SelectResult.Close() is called even got panic in fetchHandles(). | ||
for _, s := range selectResults { | ||
terror.Call(s.Close) | ||
} | ||
}() | ||
for parTblIdx, keyRange := range keyRanges { | ||
// check if this executor is closed | ||
select { | ||
|
@@ -384,6 +391,11 @@ func (e *IndexMergeReaderExecutor) startPartialIndexWorker(ctx context.Context, | |
syncErr(ctx, e.finished, fetchCh, err) | ||
return | ||
} | ||
selectResults = append(selectResults, result) | ||
failpoint.Inject("testIndexMergePartialIndexWorkerCoprLeak", func(v failpoint.Value) { | ||
time.Sleep(time.Duration(v.(int))) | ||
panic("testIndexMergePartialIndexWorkerCoprLeak") | ||
}) | ||
worker.batchSize = e.maxChunkSize | ||
if worker.batchSize > worker.maxBatchSize { | ||
worker.batchSize = worker.maxBatchSize | ||
|
@@ -401,6 +413,7 @@ func (e *IndexMergeReaderExecutor) startPartialIndexWorker(ctx context.Context, | |
if err := result.Close(); err != nil { | ||
logutil.Logger(ctx).Error("close Select result failed:", zap.Error(err)) | ||
} | ||
selectResults = selectResults[:len(selectResults)-1] | ||
cancel() | ||
e.ctx.StoreQueryFeedback(e.feedbacks[workID]) | ||
if fetchErr != nil { | ||
|
@@ -475,6 +488,13 @@ func (e *IndexMergeReaderExecutor) startPartialTableWorker(ctx context.Context, | |
partialTableReader.dagPB = e.dagPBs[workID] | ||
} | ||
|
||
var tableReaderClosed bool | ||
defer func() { | ||
// To make sure SelectResult.Close() is called even got panic in fetchHandles(). | ||
if !tableReaderClosed { | ||
terror.Call(worker.tableReader.Close) | ||
} | ||
}() | ||
for parTblIdx, tbl := range tbls { | ||
// check if this executor is closed | ||
select { | ||
|
@@ -490,6 +510,11 @@ func (e *IndexMergeReaderExecutor) startPartialTableWorker(ctx context.Context, | |
syncErr(ctx, e.finished, fetchCh, err) | ||
break | ||
} | ||
failpoint.Inject("testIndexMergePartialTableWorkerCoprLeak", func(v failpoint.Value) { | ||
time.Sleep(time.Duration(v.(int))) | ||
panic("testIndexMergePartialTableWorkerCoprLeak") | ||
}) | ||
tableReaderClosed = false | ||
worker.batchSize = e.maxChunkSize | ||
if worker.batchSize > worker.maxBatchSize { | ||
worker.batchSize = worker.maxBatchSize | ||
|
@@ -510,6 +535,7 @@ func (e *IndexMergeReaderExecutor) startPartialTableWorker(ctx context.Context, | |
if err = worker.tableReader.Close(); err != nil { | ||
logutil.Logger(ctx).Error("close Select result failed:", zap.Error(err)) | ||
} | ||
tableReaderClosed = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If worker.tableReader.Close() return a error, it will be called again in defer()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in #41647 |
||
e.ctx.StoreQueryFeedback(e.feedbacks[workID]) | ||
if fetchErr != nil { | ||
break | ||
|
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.
Why use a slice? only one element?
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.
Done