Skip to content
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: fix query hang in IndexMerge Executor when it's killed #45284

Merged
merged 4 commits into from
Jul 13, 2023
Merged
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
14 changes: 10 additions & 4 deletions executor/index_merge_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func (e *IndexMergeReaderExecutor) Next(ctx context.Context, req *chunk.Chunk) e

req.Reset()
for {
resultTask, err := e.getResultTask()
resultTask, err := e.getResultTask(ctx)
if err != nil {
return errors.Trace(err)
}
Expand All @@ -825,7 +825,7 @@ func (e *IndexMergeReaderExecutor) Next(ctx context.Context, req *chunk.Chunk) e
}
}

func (e *IndexMergeReaderExecutor) getResultTask() (*indexMergeTableTask, error) {
func (e *IndexMergeReaderExecutor) getResultTask(ctx context.Context) (*indexMergeTableTask, error) {
failpoint.Inject("testIndexMergeMainReturnEarly", func(_ failpoint.Value) {
// To make sure processWorker make resultCh to be full.
// When main goroutine close finished, processWorker may be stuck when writing resultCh.
Expand All @@ -839,8 +839,14 @@ func (e *IndexMergeReaderExecutor) getResultTask() (*indexMergeTableTask, error)
if !ok {
return nil, nil
}
if err := <-task.doneCh; err != nil {
return nil, errors.Trace(err)

select {
case <-ctx.Done():
return nil, errors.Trace(ctx.Err())
case err := <-task.doneCh:
if err != nil {
return nil, errors.Trace(err)
}
}

// Release the memory usage of last task before we handle a new task.
Expand Down