Skip to content

Commit c4f3c2b

Browse files
committed
fixed: process leak on linux in foxytest
1 parent 8384b70 commit c4f3c2b

6 files changed

+33
-2
lines changed

pkg/foxytest/add_to_group_darwin.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package foxytest
2+
3+
import (
4+
"os/exec"
5+
"syscall"
6+
)
7+
8+
func addToGroup(cmd *exec.Cmd) {
9+
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
10+
}

pkg/foxytest/add_to_group_linux.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package foxytest
2+
3+
import (
4+
"os/exec"
5+
"syscall"
6+
)
7+
8+
func addToGroup(cmd *exec.Cmd) {
9+
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
10+
}

pkg/foxytest/add_to_group_windows.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package foxytest
2+
3+
import (
4+
"os/exec"
5+
)
6+
7+
func addToGroup(cmd *exec.Cmd) {
8+
// just dummy that should not do anything, as windows already works like this
9+
}

pkg/foxytest/stop_darwin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import (
66
)
77

88
func stop(process *os.Process) error {
9-
return process.Signal(syscall.SIGTERM)
9+
return syscall.Kill(-process.Pid, syscall.SIGTERM)
1010
}

pkg/foxytest/stop_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ import (
66
)
77

88
func stop(process *os.Process) error {
9-
return process.Signal(syscall.SIGTERM)
9+
return syscall.Kill(-process.Pid, syscall.SIGTERM)
1010
}

pkg/foxytest/testsuite.go

+2
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ func (ts *testSuite) pipeOutput(t TestRunner) {
561561
func (ts *testSuite) startExecutable(t TestRunner) *exec.Cmd {
562562
//nolint:gosec // #nosec G204 -- user gives us this command to run, so they must be sure to want to run it
563563
cmd := exec.Command(ts.command, ts.args...)
564+
addToGroup(cmd)
565+
564566
in, err := cmd.StdinPipe()
565567
if err != nil {
566568
t.Fatalf("error creating stdin pipe: %v", err)

0 commit comments

Comments
 (0)