Skip to content

Commit

Permalink
Retry executable check only if text file is busy
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Nov 13, 2023
1 parent 2e12bc0 commit b0be4f1
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions pkg/autoupdate/findnew.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"runtime"
"sort"
"strings"
"syscall"
"time"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -368,21 +369,32 @@ func CheckExecutable(ctx context.Context, potentialBinary string, args ...string
return nil
}

ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
// If we get ETXTBSY error when execing, this could be because this
// binary is freshly downloaded. Retry a small number of times only
// in that circumstance.
// See: https://github.com/golang/go/issues/22315
for i := 0; i < 3; i += 1 {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

cmd := exec.CommandContext(ctx, potentialBinary, args...)
cmd := exec.CommandContext(ctx, potentialBinary, args...)

// Set env, this should prevent launcher for fork-bombing
cmd.Env = append(cmd.Env, "LAUNCHER_SKIP_UPDATES=TRUE")
// Set env, this should prevent launcher for fork-bombing
cmd.Env = append(cmd.Env, "LAUNCHER_SKIP_UPDATES=TRUE")

execErr := cmd.Run()
execErr := cmd.Run()
if execErr != nil && errors.Is(ctx.Err(), syscall.ETXTBSY) {
continue
}

if ctx.Err() != nil {
return ctx.Err()
}

if ctx.Err() != nil {
return ctx.Err()
return supressRoutineErrors(execErr)
}

return supressRoutineErrors(execErr)
return fmt.Errorf("could not exec %s -- text file busy", potentialBinary)
}

// supressRoutineErrors attempts to tell whether the error was a
Expand Down

0 comments on commit b0be4f1

Please sign in to comment.