Skip to content

Commit

Permalink
Merge pull request #763 from saschagrunert/version-retry
Browse files Browse the repository at this point in the history
Retry exec commands on text file busy
  • Loading branch information
bboreham authored Apr 22, 2020
2 parents acc3dad + e2a7366 commit 7743645
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/invoke/raw_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"
"os/exec"
"strings"
"time"

"github.com/containernetworking/cni/pkg/types"
)
Expand All @@ -37,7 +39,24 @@ func (e *RawExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData [
c.Stdin = bytes.NewBuffer(stdinData)
c.Stdout = stdout
c.Stderr = stderr
if err := c.Run(); err != nil {

// Retry the command on "text file busy" errors
for i := 0; i <= 5; i++ {
err := c.Run()

// Command succeeded
if err == nil {
break
}

// If the plugin is currently about to be written, then we wait a
// second and try it again
if strings.Contains(err.Error(), "text file busy") {
time.Sleep(time.Second)
continue
}

// All other errors except than the busy text file
return nil, e.pluginErr(err, stdout.Bytes(), stderr.Bytes())
}

Expand Down

0 comments on commit 7743645

Please sign in to comment.