-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
store/tikv: call Next() after copIterator closed lead to goroutine leak #5624
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,15 @@ func (it *copIterator) run(ctx goctx.Context) { | |
}) | ||
} | ||
|
||
func recvFromRespCh(respCh <-chan copResponse, finished <-chan struct{}) (resp copResponse, ok bool, exit bool) { | ||
select { | ||
case resp, ok = <-respCh: | ||
case <-finished: | ||
exit = true | ||
} | ||
return | ||
} | ||
|
||
func (it *copIterator) sendToTaskCh(ctx goctx.Context, t *copTask, taskCh chan<- *copTask) (finished bool, canceled bool) { | ||
select { | ||
case taskCh <- t: | ||
|
@@ -421,13 +430,18 @@ func (it *copIterator) Next() ([]byte, error) { | |
return nil, nil | ||
} | ||
} else { | ||
var closed bool | ||
for { | ||
if it.curr >= len(it.tasks) { | ||
// Resp will be nil if iterator is finished. | ||
return nil, nil | ||
} | ||
task := it.tasks[it.curr] | ||
resp, ok = <-task.respChan | ||
resp, ok, closed = recvFromRespCh(task.respChan, it.finished) | ||
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. s/closed/exit/ or s/exit/closed/ 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. I think closed is better, you see the comment line in the next line: |
||
if closed { | ||
// Close() is already called, so Next() is invalid. | ||
return nil, nil | ||
} | ||
if ok { | ||
break | ||
} | ||
|
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 not just close the task.respChan in copIterator.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.
Because send to a closed channel would panic.