Skip to content

Commit

Permalink
fix: populate timeout context to node-collector (#120)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <[email protected]>
  • Loading branch information
chen-keinan authored Mar 4, 2023
1 parent 0e59498 commit 86f7019
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ func (r *runner) runAndWaitForever() error {
}

func (r *runner) runWithTimeout(ctx context.Context) error {
ctxWithTimeout := ctx
// context timeout also can be set on caller side
if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctxWithTimeout, cancel = context.WithTimeout(ctx, r.timeoutDuration)
ctx, cancel = context.WithTimeout(ctx, r.timeoutDuration)
defer cancel()
}
klog.V(3).Infof("Running task with timeout: %v", r.timeoutDuration)
Expand All @@ -92,7 +91,7 @@ func (r *runner) runWithTimeout(ctx context.Context) error {
klog.V(3).Infof("Stopping runner on task completion with error: %v", err)
return err
// Signaled when we run out of time.
case <-ctxWithTimeout.Done():
case <-ctx.Done():
klog.V(3).Info("Stopping runner on timeout")
return ErrTimeout
}
Expand Down

0 comments on commit 86f7019

Please sign in to comment.