Skip to content

Commit

Permalink
check if context has a deadline (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeidiDeng committed Jun 25, 2023
1 parent c9644d6 commit 4227917
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,13 @@ func parseAndAppendFlags(cmd *exec.Cmd, flags string) *exec.Cmd {
}

func (env environment) runCommand(ctx context.Context, cmd *exec.Cmd) error {
deadline, _ := ctx.Deadline()
log.Printf("[INFO] exec (timeout=%s): %+v ", time.Until(deadline), cmd)
deadline, ok := ctx.Deadline()
var timeout time.Duration
// context doesn't necessarily have a deadline
if ok {
timeout = time.Until(deadline)
}
log.Printf("[INFO] exec (timeout=%s): %+v ", timeout, cmd)

// start the command; if it fails to start, report error immediately
err := cmd.Start()
Expand Down

0 comments on commit 4227917

Please sign in to comment.