Skip to content

Commit 9f57b57

Browse files
mbertroneclaude
andcommitted
fix(gpu): stop the events gatherer before reinstalling the NVML mock
TestMetricNamesWithoutEBPFProbes calls collectMetricNames twice, and each call installs a fresh global NVML mock via setupMockDevices. The events gatherer was stopped from a t.Cleanup, which does not run until the whole test ends, so the first call's asyncFetchWorker was still reading the global through EventSetWait while the second call wrote it. The race detector flagged it in CI (both the go test and bazel jobs run -race); it did not reproduce locally because I ran without -race. Stop the gatherer with a defer inside the helper instead. Stop() joins the worker via wg.Wait(), so the worker is gone before the next setup. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a0132ce commit 9f57b57

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pkg/collector/corechecks/gpu/nvidia/collector_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,14 @@ func collectMetricNames(t *testing.T, spCache *SystemProbeCache) map[string]stru
379379
testutil.WithArchitecture("blackwell"),
380380
)
381381

382+
// Stop the gatherer before returning instead of registering a t.Cleanup: its
383+
// worker goroutine reads the global NVML mock, and the caller invokes this
384+
// helper again, which installs a fresh one. A t.Cleanup would not run until
385+
// the whole test ends, leaving the first worker racing the second setup.
386+
// Stop() joins the worker, so the two can never overlap.
382387
eventsGatherer := NewDeviceEventsGatherer()
383388
require.NoError(t, eventsGatherer.Start())
384-
t.Cleanup(func() { require.NoError(t, eventsGatherer.Stop()) })
389+
defer func() { require.NoError(t, eventsGatherer.Stop()) }()
385390

386391
deps := &CollectorDependencies{
387392
DeviceEventsGatherer: eventsGatherer,

0 commit comments

Comments
 (0)