From e562dc0606901866fefb276b411b9112eb91552b Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Thu, 8 Oct 2026 14:49:52 -0700 Subject: [PATCH] test(doltserver): kill nc's process group in TestListenerOwnership_RealTools The test starts sh -c "nc -l 127.0.0.1 ; exit 0" (the trailing exit keeps sh from exec-ing nc, so the listener is a grandchild) and its cleanup killed only sh. Killing a shell does not kill the child it forked: nc is orphaned, keeps listening, and stays in go test's process group after the test ends. Give sh and nc their own process group and kill the group in cleanup. Found by a macOS CI harness that fails a run when any process outlives go test ("left descendants after exit"). PR CI here has no macOS test job, so the leak does not show in this repository's checks. --- internal/doltserver/listenerowner_darwin_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/doltserver/listenerowner_darwin_test.go b/internal/doltserver/listenerowner_darwin_test.go index 01f514d37..7ddcb17b3 100644 --- a/internal/doltserver/listenerowner_darwin_test.go +++ b/internal/doltserver/listenerowner_darwin_test.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "strconv" + "syscall" "testing" "time" ) @@ -111,10 +112,14 @@ func TestListenerOwnership_RealTools(t *testing.T) { // shell that does not exec it, so the listener is a grandchild. ncPort := freeLoopbackPort(t) cmd := exec.Command("sh", "-c", "nc -l 127.0.0.1 "+strconv.Itoa(ncPort)+"; exit 0") + // Killing only sh would orphan nc, which keeps listening after the test + // (and in go test's process group). Give the pair its own group and + // kill the group in cleanup. + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} if err := cmd.Start(); err != nil { t.Skipf("cannot start nc under sh: %v", err) } - t.Cleanup(func() { _ = cmd.Process.Kill(); _ = cmd.Wait() }) + t.Cleanup(func() { _ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL); _ = cmd.Wait() }) deadline := time.Now().Add(5 * time.Second) for { pids, err := listeningPIDs(ncPort)