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

store/tikv: Fix goroutine leak in tikv client (#20808) #20863

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ func (s *tikvStore) Close() error {
s.txnLatches.Close()
}
s.regionCache.Close()

if err := s.kv.Close(); err != nil {
return errors.Trace(err)
}
return nil
}

Expand Down
11 changes: 11 additions & 0 deletions store/tikv/safepoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
type SafePointKV interface {
Put(k string, v string) error
Get(k string) (string, error)
Close() error
}

// MockSafePointKV implements SafePointKV at mock test
Expand Down Expand Up @@ -74,6 +75,11 @@ func (w *MockSafePointKV) Get(k string) (string, error) {
return elem, nil
}

// Close implements the Close method for SafePointKV
func (w *MockSafePointKV) Close() error {
return nil
}

// EtcdSafePointKV implements SafePointKV at runtime
type EtcdSafePointKV struct {
cli *clientv3.Client
Expand Down Expand Up @@ -113,6 +119,11 @@ func (w *EtcdSafePointKV) Get(k string) (string, error) {
return "", nil
}

// Close implements the Close for SafePointKV
func (w *EtcdSafePointKV) Close() error {
return errors.Trace(w.cli.Close())
}

func saveSafePoint(kv SafePointKV, key string, t uint64) error {
s := strconv.FormatUint(t, 10)
err := kv.Put(GcSavedSafePoint, s)
Expand Down