- Notifications
You must be signed in to change notification settings - Fork1.1k
ci: improve 'tfail in goroutine' ruleguard rule#19682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ethanndickson commentedSep 3, 2025
| go func($*_){ | ||
| $*_ | ||
| $require.$_($*_) | ||
| require.$_($*_) | ||
| $*_ | ||
| }($*_)`). | ||
| At(m["require"]). | ||
| Where(m["require"].Text=="require"). |
ethanndicksonSep 3, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The prior version would only match on the first line in the goroutine of the form<A>.<B>(<C>), meaning the rule wouldn't fire a violation if therequire.* came after some otherselector.Func. Ruleguard's pretty limited, and neither I nor Blink could find a way to make the matching not greedy.
To fix, we're just going to only match on lines where the selector isrequires.
| m.Match(` | ||
| go func($*_){ | ||
| $*_ | ||
| $t.$fail($*_) | ||
| t.$fail($*_) | ||
| $*_ | ||
| }($*_)`). | ||
| At(m["fail"]). | ||
| Where(m["t"].Type.Implements("testing.TB")&&m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")). | ||
| Where(m["fail"].Text.Matches("^(FailNow|Fatal|Fatalf)$")). | ||
| Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We apply the same idea here, but with a caveat that if there's some othert.* function that's called before thet.Fail/whatever the rule won't fire. It's not perfect, but it's probably good enough.
7eba8dd to10d0f7fCompare
johnstcn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for improving this! Ruleguard DSL is tricky at the best of times.
50704a5 intomainUh oh!
There was an error while loading.Please reload this page.

Uh oh!
There was an error while loading.Please reload this page.
This PR improves the ruleguard rule for detecting
t.Failcalls in goroutines. It picks up additional violations, of which are fixed in this PR.See self-review for details.
The motivation for fixing this comes from a flake I fixed in#19599, where tests would fail from a
requirein anEventually.