Skip to content

Commit

Permalink
store/tikv: Fix goroutine leak in tikv client (#20808)
Browse files Browse the repository at this point in the history
Signed-off-by: MyonKeminta <[email protected]>
  • Loading branch information
MyonKeminta authored Nov 5, 2020
1 parent 4e1cbca commit 8c418b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ func (s *tikvStore) Close() error {
if s.coprCache != nil {
s.coprCache.cache.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 @@ -46,6 +46,7 @@ type SafePointKV interface {
Put(k string, v string) error
Get(k string) (string, error)
GetWithPrefix(k string) ([]*mvccpb.KeyValue, error)
Close() error
}

// MockSafePointKV implements SafePointKV at mock test
Expand Down Expand Up @@ -90,6 +91,11 @@ func (w *MockSafePointKV) GetWithPrefix(prefix string) ([]*mvccpb.KeyValue, erro
return kvs, 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 @@ -140,6 +146,11 @@ func (w *EtcdSafePointKV) GetWithPrefix(k string) ([]*mvccpb.KeyValue, error) {
return resp.Kvs, nil
}

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

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

0 comments on commit 8c418b9

Please sign in to comment.