mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Data race fixes in tests and a new semgrep rule (#14594)
* test: don't use loop vars in goroutines fixes a data race in the test * test: copy objects in statestore before mutating fixes data race in test * test: @lgfa29's segmgrep rule for loops/goroutines Found 2 places where we were improperly using loop variables inside goroutines.
This commit is contained in:
28
.semgrep/loopclosure.yml
Normal file
28
.semgrep/loopclosure.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
rules:
|
||||
- id: loopclosure
|
||||
patterns:
|
||||
- pattern-inside: |
|
||||
for $A, $B := range $C {
|
||||
...
|
||||
}
|
||||
- pattern-inside: |
|
||||
go func() {
|
||||
...
|
||||
}()
|
||||
- pattern-not-inside: |
|
||||
go func(..., $B, ...) {
|
||||
...
|
||||
}(..., $B, ...)
|
||||
- pattern-not-inside: |
|
||||
go func() {
|
||||
...
|
||||
for ... {
|
||||
...
|
||||
}
|
||||
...
|
||||
}()
|
||||
- pattern: $B
|
||||
message: Loop variable $B used inside goroutine
|
||||
languages:
|
||||
- go
|
||||
severity: WARNING
|
||||
Reference in New Issue
Block a user