Add semgrep rule to catch non-determinism in FSM (#13725)

See `message:` in rule for details.

Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
This commit is contained in:
Michael Schurter 2022-07-12 15:44:24 -07:00 committed by GitHub
parent b656981cf0
commit e44d6f09d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

26
.semgrep/fsm_time.yml Normal file
View File

@ -0,0 +1,26 @@
rules:
- id: "no-time-in-fsm"
patterns:
- pattern: time.Now()
# Metric state is local to the server and therefore must use time.
- pattern-not-inside: |
defer metrics.MeasureSince(...)
# The timetable's whole point is to roughly track timestamps for Raft log
# indexes, so it must use time.
- pattern-not-inside: |
$N.timetable.Witness(...)
message: |
time.Now() should not be called from within the Server's FSM. Apply Raft
log messages to the State Store must be deterministic so that each server
contains exactly the same state. Since time drifts between nodes, it must
be set before the Raft log message is applied so that all Raft members
see the same timestamp.
languages:
- "go"
severity: "WARNING"
paths:
include:
- "nomad/fsm.*"
- "nomad/state/state_store.*"