Skip to content

Commit

Permalink
Retry exec commands on text file busy
Browse files Browse the repository at this point in the history
This makes the plugin validation a bit more robust by retrying the
execution if the plugin is in text file busy state. This can happen if
we write the config and the plugin at once. To avoid such races we now
try up to 5 seconds for the plugin validation.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
  • Loading branch information
saschagrunert committed Apr 16, 2020
1 parent bf84331 commit e2a7366
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 e2a7366

Please sign in to comment.