Skip to content

Commit

Permalink
fix: possible goroutine leak in exec
Browse files Browse the repository at this point in the history
If timeout happens and ShouldWait is false (default) cmd.Wait()
goroutine will stack forever on sending to done channel.
The will be no receiver from done.
Making the channel buffered lets the goroutine exit.

Signed-off-by: Anton Tiurin <[email protected]>
  • Loading branch information
noxiouz committed Jul 8, 2023
1 parent 86df781 commit 57d950d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error) {
return "", err
}

done := make(chan error)
done := make(chan error, 1)
go func() { done <- cmd.Wait() }()

// Start a timer
Expand Down

0 comments on commit 57d950d

Please sign in to comment.