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

config: fix goroutine leak risk #3091

Merged
merged 1 commit into from
Oct 22, 2020
Merged

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Oct 21, 2020

Signed-off-by: Song Gao disxiaofei@163.com

What problem does this PR solve?

What is changed and how it works?

The SetTTLData may have goroutine leak as NewStringTTL would create an extra goroutine to do the gc work. When updating an existed key, we need to call the cancel function to close the extra goroutine.

// SetTTLData set temporary configuration
func (o *PersistOptions) SetTTLData(ctx context.Context, key string, value interface{}, ttl time.Duration) {
	if data, ok := o.ttl[key]; ok {
		data.Clear()
                // the goroutine would leak here
	}
	o.ttl[key] = cache.NewStringTTL(ctx, 5*time.Second, ttl)
	o.ttl[key].Put(key, value)
}

As the origin context is directly use the server context, this request fix it by replace a new context which is success from the server context and maintained its cancel function.

Release note

Signed-off-by: Song Gao <disxiaofei@163.com>
@Yisaer Yisaer added needs-cherry-pick-release-4.0 The PR needs to cherry pick to release-4.0 branch. type/bugfix This PR fixes a bug. labels Oct 21, 2020
Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 22, 2020
@Yisaer Yisaer added the require-LGT1 Indicates that the PR requires an LGTM. label Oct 22, 2020
@Yisaer
Copy link
Contributor Author

Yisaer commented Oct 22, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 22, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@@ -35,6 +35,7 @@ import (
type PersistOptions struct {
// configuration -> ttl value
ttl map[string]*cache.TTLString
ttlCancel map[string]context.CancelFunc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why create cache.TTLString for each key, instead of use only 1 cache.TTLString for all keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each configuration, they could have different ttl.

@ti-srebot ti-srebot merged commit 6077550 into tikv:master Oct 22, 2020
ti-srebot pushed a commit to ti-srebot/pd that referenced this pull request Oct 22, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #3094

Yisaer added a commit that referenced this pull request Oct 22, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Song Gao <disxiaofei@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-4.0 The PR needs to cherry pick to release-4.0 branch. require-LGT1 Indicates that the PR requires an LGTM. status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants