What changed:
- group.kill's retry loop outlives its caller: it keeps signalling a
process group every 5ms for up to 10s after the caller (a probe's
cmd.Cancel on exec's watchCtx goroutine) has gone. It read the package
var signalGroup on every pass, so a test that swaps the var for its own
and puts the old one back when it ends (TestProbeKillEndsWhatTheSignal-
Missed's cleanup) raced the loop's reads: go test -race ./internal/proc/
went red with "WARNING: DATA RACE" (write at probe_test.go:151, read at
tree_other.go:43), 5 of 5 runs.
- kill now takes the kill function once at its entry and the loop uses
that copy. In production nothing changes (the var is never written);
a test's swap is seen by every kill started after it, and a loop under
way finishes with the function it was started with, which is the one
that must answer whether the group is empty.
Run:
- go test -race -tags nogui -count=1 -run TestProbeKillEndsWhatTheSignalMissed
./internal/proc/: FAIL with DATA RACE without the change (1 warning,
5 of 5 runs), ok with it, and -race -count=20 ok.
- go test -race -tags nogui -count=1 and -count=1 ./internal/proc/ ok.
Nothing else in the tree reads or writes signalGroup (grep).
Review: on main (3f5702421) go test -race -count=5 -run
TestProbeKillEndsWhatTheSignalMissed ./internal/proc reported 4 DATA RACE
warnings: the cleanup's write (probe_test.go:151) and the next run's swap
(probe_test.go:141) against the loop's read (tree_other.go:43), and one
run failed. With the change -race -count=30 is ok and the whole package
is ok under -race.
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>