[test] Call cmd.Start and cmd.Wait separately to avoid triggering race detector#616
Merged
SuperQ merged 2 commits intoprometheus:masterfrom Jul 8, 2017
jeromefroe:jeromefroe/fix-race-condition-in-test
Merged
[test] Call cmd.Start and cmd.Wait separately to avoid triggering race detector#616SuperQ merged 2 commits intoprometheus:masterfrom jeromefroe:jeromefroe/fix-race-condition-in-test
SuperQ merged 2 commits intoprometheus:masterfrom
jeromefroe:jeromefroe/fix-race-condition-in-test
Conversation
Member
|
Want to add |
Contributor
Author
|
Hey, yep, just pushed a change to enable the race detector during tests in the Makefile. |
oblitorum
pushed a commit
to shatteredsilicon/node_exporter
that referenced
this pull request
Apr 9, 2024
…e detector (prometheus#616) * [test] Call cmd.Start and cmd.Wait separately to avoid triggering race detector * [test] Enable race detector for tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi!
I noticed that currently the tests in
node_exporter.gofail when run with the race detector. For example, on master:The issue is that
runCommandAndTestscallscmd.Runin a separate goroutine from the one in which it gets the pid for the process by callingcmd.Process.Pid. This causes the race detector to trigger because it sees an unsynchronized write and read to the same variable in separate goroutines.cmd.Runcallscmd.Start, which updates theProcessfield forcmd, and then waits for thecmd.Waitto return. Consequently, we can avoid triggering the race detector by callingcmd.Startourselves and then callingcmd.Waitin a separate goroutine. This fixes the race because now the write and read ofcmd.Processoccur in the same goroutine. For example, on my branch: