Skip to content

Commit

Permalink
config: fix goroutine leak risk (#3091)
Browse files Browse the repository at this point in the history
Signed-off-by: Song Gao <disxiaofei@163.com>
  • Loading branch information
Yisaer authored Oct 22, 2020
1 parent dcc1b82 commit 6077550
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
type PersistOptions struct {
// configuration -> ttl value
ttl map[string]*cache.TTLString
ttlCancel map[string]context.CancelFunc
schedule atomic.Value
replication atomic.Value
pdServerConfig atomic.Value
Expand All @@ -53,6 +54,7 @@ func NewPersistOptions(cfg *Config) *PersistOptions {
o.labelProperty.Store(cfg.LabelProperty)
o.SetClusterVersion(&cfg.ClusterVersion)
o.ttl = make(map[string]*cache.TTLString, 6)
o.ttlCancel = make(map[string]context.CancelFunc, 6)
return o
}

Expand Down Expand Up @@ -597,12 +599,15 @@ func (o *PersistOptions) CheckLabelProperty(typ string, labels []*metapb.StoreLa
}

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

func (o *PersistOptions) getTTLData(key string) (interface{}, bool) {
Expand Down

0 comments on commit 6077550

Please sign in to comment.