Skip to content

fix: move exec inside loop - #1183

Open
QxBytes wants to merge 2 commits into
containernetworking:mainfrom
QxBytes:alew/run-exec-inside-loop
Open

fix: move exec inside loop#1183
QxBytes wants to merge 2 commits into
containernetworking:mainfrom
QxBytes:alew/run-exec-inside-loop

Conversation

@QxBytes

@QxBytes QxBytes commented Apr 21, 2026

Copy link
Copy Markdown

Aims to resolve #855

Moves exec command into the for loop so each retry gets a new instance of the command. Previously, we would retry using the same exec command which would always fail due to https://cs.opensource.google/go/go/+/refs/tags/go1.26.2:src/os/exec/exec.go;l=146 (command cannot be reused after calling Run on it).

Reran the unit test several dozen times without any flakiness.

@QxBytes
QxBytes force-pushed the alew/run-exec-inside-loop branch 2 times, most recently from 508d95f to 1439246 Compare April 21, 2026 21:53
aims to resolve containernetworking#855

Signed-off-by: QxBytes <39818795+QxBytes@users.noreply.github.com>
@QxBytes
QxBytes force-pushed the alew/run-exec-inside-loop branch from 1439246 to fdc67a2 Compare April 21, 2026 21:57
@QxBytes
QxBytes marked this pull request as ready for review April 21, 2026 22:40
@MikeZappa87

Copy link
Copy Markdown
Contributor

@squeed @LionelJouin this might have been under the radar for awhile

@jellonek jellonek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO good idea + nice tests, while implementation - i'm not sure about it...

Comment thread pkg/invoke/raw_exec.go Outdated
// Retry the command on "text file busy" errors
for i := 0; i <= 5; i++ {
stdout = &bytes.Buffer{}
stderr = &bytes.Buffer{}

@jellonek jellonek May 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you are creating new objects instead of just calling https://pkg.go.dev/bytes#Buffer.Reset at the start of each iteration?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR

Comment thread pkg/invoke/raw_exec.go
stdout = &bytes.Buffer{}
stderr = &bytes.Buffer{}
c := exec.CommandContext(ctx, pluginPath)
c.Env = environ

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a possibility that c.Env could change between iterations?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c.Env would come from environ which I don't expect to change during the lifetime of the call.

Comment thread pkg/invoke/raw_exec.go
stderr = &bytes.Buffer{}
c := exec.CommandContext(ctx, pluginPath)
c.Env = environ
c.Stdin = bytes.NewBuffer(stdinData)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you are recreating it again and again, while it could be simply resetted?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I resetted like stdout or stderr I'd need to write the stdinData back in right? I expect the retries case to be hit very rarely.

Signed-off-by: Alexander <39818795+QxBytes@users.noreply.github.com>
@QxBytes
QxBytes requested a review from jellonek May 18, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run c := exec.CommandContext(ctx, pluginPath) inside the for loop

3 participants