Skip to content

Commit 26e2b4d

Browse files
committed
Use context.WithCancel for progress updater and pass cancel to it
1 parent 3ec2c8b commit 26e2b4d

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

pkg/runner/chunk_runner.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,10 @@ func (r *ChunkRunner) process(continues <-chan struct{}, chunk *v1alpha1.Chunk)
547547

548548
var gsr *readCount
549549
var gdrs []*swmrCount
550-
ctx := context.Background()
551550

552-
stopProgress := r.startProgressUpdater(ctx, s, &gsr, &gdrs)
551+
ctx, cancel := context.WithCancel(context.Background())
552+
553+
stopProgress := r.startProgressUpdater(ctx, cancel, s, &gsr, &gdrs)
553554
defer stopProgress()
554555

555556
body, contentLength := r.sourceRequest(ctx, chunk, s)
@@ -692,14 +693,12 @@ func (r *ChunkRunner) process(continues <-chan struct{}, chunk *v1alpha1.Chunk)
692693
r.handleSha256AndFinalize(continues, chunk, s, swmr, etags)
693694
}
694695

695-
func (r *ChunkRunner) startProgressUpdater(ctx context.Context, s *state, gsr **readCount, gdrs *[]*swmrCount) func() {
696+
func (r *ChunkRunner) startProgressUpdater(ctx context.Context, cancel func(), s *state, gsr **readCount, gdrs *[]*swmrCount) func() {
696697
var (
697698
prevStatus *v1alpha1.ChunkStatus
698699
lastUpdateTime = time.Now()
699700
)
700701

701-
ctx, cancel := context.WithCancel(ctx)
702-
703702
chunkFunc := func() {
704703
s.Update(func(ss *v1alpha1.Chunk) *v1alpha1.Chunk {
705704
if *gsr != nil {

0 commit comments

Comments
 (0)