Skip to content

Commit

Permalink
store/tikv: fix goroutine leak in gcworker (#10622) (#10683)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and zz-jason committed Jun 4, 2019
1 parent 3daeff5 commit bff7dac
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions store/tikv/range_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ func (s *RangeTaskRunner) RunOnRange(ctx context.Context, startKey []byte, endKe
key := startKey
for {
select {
case <-ctx.Done():
return errors.Trace(ctx.Err())
case <-statLogTicker.C:
logutil.Logger(ctx).Info("range task in progress",
zap.String("name", s.name),
Expand Down Expand Up @@ -168,7 +166,12 @@ func (s *RangeTaskRunner) RunOnRange(ctx context.Context, startKey []byte, endKe
}

pushTaskStartTime := time.Now()
taskCh <- task

select {
case taskCh <- task:
case <-ctx.Done():
break
}
metrics.TiKVRangeTaskPushDuration.WithLabelValues(s.name).Observe(time.Since(pushTaskStartTime).Seconds())

if isLast {
Expand Down Expand Up @@ -247,8 +250,6 @@ func (w *rangeTaskWorker) run(ctx context.Context, cancel context.CancelFunc) {
}

completedRegions, err := w.handler(ctx, *r)
atomic.AddInt32(w.completedRegions, int32(completedRegions))

if err != nil {
logutil.Logger(ctx).Info("canceling range task because of error",
zap.String("name", w.name),
Expand All @@ -259,5 +260,6 @@ func (w *rangeTaskWorker) run(ctx context.Context, cancel context.CancelFunc) {
cancel()
break
}
atomic.AddInt32(w.completedRegions, int32(completedRegions))
}
}

0 comments on commit bff7dac

Please sign in to comment.