* fix(windows): report Dolt server run-state correctly isServerProbablyRunning() checked the server PID with proc.Signal(syscall.Signal(0)), the Unix null-signal probe. Windows has no signals (os.Process.Signal rejects everything but Kill), so the probe always errored and every live PID looked dead -- bd doctor / drift always reported the shared Dolt server as not running on Windows. An existence-only replacement is wrong too: on Windows a terminated process's kernel object stays openable while any handle to it lingers (an un-Wait()ed parent, AV/EDR, a debugger, Task Manager), so it reports a dead server as alive for a window after exit. Split the probe into a build-tagged processAlive(pid), matching internal/doltserver and internal/linear: Unix keeps Signal(0); Windows uses OpenProcess(SYNCHRONIZE|PROCESS_QUERY_LIMITED_INFORMATION) + WaitForSingleObject(h,0) + CloseHandle -- a terminated process's handle is signaled (WAIT_OBJECT_0), a running one times out (WAIT_TIMEOUT). Unix behavior is unchanged. Adds a Windows regression test that reproduces the lingering-handle false positive deterministically (fails on the naive OpenProcess-success probe, passes on this fix). Agent-Signature: claude-code-opus-4.8-high on behalf of Marco Del Pin * fix(windows): address #4808 review: WAIT_OBJECT_0 precondition, Windows PR-time test lane, naming - Require WAIT_OBJECT_0 from WaitForSingleObject in the lingering-handle test precondition (the pinned x/sys returns nil error on WAIT_TIMEOUT; only WAIT_FAILED errors), matching the pattern of the newer Windows tests in internal/doltserver and internal/linear. - Add a targeted windows-latest PR-time job (test-windows-liveness) running the ^TestIsServerProbablyRunning tests, wired into the CI gate: the //go:build windows regression test is compiled out on the Ubuntu jobs, and main.yml's Windows job is push-to-main build/smoke only, so without this lane the regression guard never executes at PR time. - Rename h/s to processHandle/waitResult in processAlive. Scope note (review should-fix 1): this PR fixes the bd config drift probe only, processAlive's single production caller. bd doctor's server run-state goes through doltserver.IsRunning, fixed separately upstream by594c464cc. * fix(windows): rename processAlive to pidAlive to avoid merge-ref collision with #5004 test helper Upstreambb9bb7487(#5004, merged 2026-07-24) added a test-only processAlive helper in cmd/bd/proxied_local_helpers_test.go (//go:build cgo && unix). On the PR merge ref both declarations coexist in package main and the cgo unix lanes fail to compile (processAlive redeclared - Build (Embedded Dolt) + PR Core). Renaming the production helper introduced by this PR is the minimal fix; the #5004 test helper is untouched. * fix(windows): check CloseHandle in pidAlive to satisfy errcheck The PR gate went red after the maintainer merge of current main wired the windows lint lane into ci-gate: cmd/bd/config_drift_windows.go:26:27: Error return value of windows.CloseHandle is not checked (errcheck) failing both Build Artifacts and PR Lint (wrapper timing) on run 30422840210. Adopt the pattern every other windows file in the tree already uses for a deferred handle close - doltserver_windows.go:110, synclock_windows.go:14, procid_windows.go:35/47, process_executable_windows.go:21: defer func() { _ = windows.CloseHandle(processHandle) }() This file was the only defer windows.CloseHandle(...) without the wrapper. Verified with the linter itself rather than by inspection: errcheck v1.20.0, GOOS=windows, -tags gms_pure_go. fixed tree -> 0 hits on config_drift_windows.go:26 line reverted -> 1 hit on config_drift_windows.go:26 so the check demonstrably goes red on the old line and green on the new one. Also GOOS=windows go vet ./cmd/bd clean, gofmt clean. The three remaining bare CloseHandle calls in config_drift_windows_test.go are deliberately untouched: .golangci.yml sets tests: false, which is why CI named only line 26. --------- Co-authored-by: Test <test@test.com> Co-authored-by: matt wilkie <maphew@gmail.com> Co-authored-by: Marco Del Pin <marco@omniaevo.it>
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
"github.com/steveyegge/beads/internal/doltserver"
|
|
)
|
|
|
|
// TestIsServerProbablyRunningReportsDeadPIDWithLingeringHandle guards the
|
|
// Windows liveness probe against the lingering-handle false positive.
|
|
//
|
|
// On Windows a terminated process's kernel object stays openable for as long
|
|
// as any handle to it remains open anywhere on the system. An existence-only
|
|
// probe (OpenProcess / os.FindProcess succeeds) therefore reports a dead
|
|
// server as alive. This test reproduces exactly that: it starts a child that
|
|
// exits immediately and deliberately never Wait()s it, so os/exec keeps a
|
|
// lingering handle open; it confirms the child has actually terminated, then
|
|
// asserts the drift probe reports it dead.
|
|
func TestIsServerProbablyRunningReportsDeadPIDWithLingeringHandle(t *testing.T) {
|
|
cmd := exec.Command("cmd.exe", "/c", "exit")
|
|
if err := cmd.Start(); err != nil {
|
|
t.Fatalf("start child: %v", err)
|
|
}
|
|
pid := cmd.Process.Pid
|
|
// Reap the child at the end; until then cmd.Process keeps a handle open,
|
|
// which is the lingering reference that defeats an existence-only probe.
|
|
defer func() { _ = cmd.Wait() }()
|
|
|
|
// Confirm the child has really exited, via a SEPARATE probe handle so we do
|
|
// not disturb the lingering one held by cmd.Process.
|
|
probe, err := windows.OpenProcess(windows.SYNCHRONIZE, false, uint32(pid))
|
|
if err != nil {
|
|
t.Skipf("cannot open probe handle for pid %d: %v", pid, err)
|
|
}
|
|
status, err := windows.WaitForSingleObject(probe, 5000)
|
|
if err != nil {
|
|
windows.CloseHandle(probe)
|
|
t.Fatalf("waiting for child to exit: %v", err)
|
|
}
|
|
if status != windows.WAIT_OBJECT_0 {
|
|
windows.CloseHandle(probe)
|
|
t.Fatalf("wait for process %d returned status %#x, want WAIT_OBJECT_0", pid, status)
|
|
}
|
|
windows.CloseHandle(probe)
|
|
|
|
beadsDir := t.TempDir()
|
|
pidFile := filepath.Join(beadsDir, doltserver.PIDFileName)
|
|
if err := os.WriteFile(pidFile, []byte(strconv.Itoa(pid)+"\n"), 0o600); err != nil {
|
|
t.Fatalf("write pid file: %v", err)
|
|
}
|
|
|
|
if isServerProbablyRunning(beadsDir) {
|
|
t.Errorf("dead pid %d reported as running (lingering-handle false positive)", pid)
|
|
}
|
|
}
|