check if context has a deadline (#146)

This commit is contained in:
WeidiDeng 2023-06-25 10:59:28 +08:00 committed by GitHub
parent c9644d6e6b
commit 4227917de2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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()