From 54c747adffacea8beec17efb217ca3ec3cf9b1a5 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Mon, 16 Nov 2026 07:59:39 -0500 Subject: [PATCH] fix(test): end the startup helper when its test process is gone The detached helper looped forever, and a cancelled launch could return before the helper recorded its pid, so the test's cleanup could not kill it. Under parallel load 24 runs left 167 helpers behind; the helper now watches its owner's pid and exits, leaving none. --- cli/internal/localdaemon/startup_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cli/internal/localdaemon/startup_test.go b/cli/internal/localdaemon/startup_test.go index 78762f0b4..f15d95224 100644 --- a/cli/internal/localdaemon/startup_test.go +++ b/cli/internal/localdaemon/startup_test.go @@ -15,6 +15,7 @@ import ( "strconv" "strings" "sync/atomic" + "syscall" "testing" "time" ) @@ -24,6 +25,7 @@ func TestStartupHelperProcess(t *testing.T) { if mode == "" { return } + go exitWithOwner() if scale, err := strconv.Atoi(os.Getenv("ALBEDO_STARTUP_TEST_SCALE")); err == nil { startupScale = time.Duration(scale) } @@ -67,6 +69,24 @@ func TestStartupHelperProcess(t *testing.T) { } } +// exitWithOwner ends the helper once the test process that started it is +// gone. The helper runs detached, and a test that returns before the helper +// records its pid (a cancelled launch) cannot kill it from its cleanup. +func exitWithOwner() { + owner, err := strconv.Atoi(os.Getenv("ALBEDO_STARTUP_TEST_OWNER")) + if err != nil { + panic("the startup helper has no owner: " + err.Error()) + } + process, err := os.FindProcess(owner) + if err != nil { + os.Exit(0) + } + for process.Signal(syscall.Signal(0)) == nil { + time.Sleep(200 * time.Millisecond) + } + os.Exit(0) +} + // serveOnRecordedPort is a daemon that binds the port a dead daemon's // daemon.json names before it publishes its own record. func serveOnRecordedPort(home string, mode string) { @@ -155,6 +175,7 @@ func startupHelper(t *testing.T, mode string) string { } t.Setenv("ALBEDO_DAEMON", wrapper) t.Setenv("ALBEDO_STARTUP_TEST_HELPER", mode) + t.Setenv("ALBEDO_STARTUP_TEST_OWNER", strconv.Itoa(os.Getpid())) t.Cleanup(func() { data, err := os.ReadFile(filepath.Join(home, "helper.pid")) if err == nil { -- knotmirror 0.0.1