Unverified Commit be2262eb authored by Michael Schurter's avatar Michael Schurter Committed by GitHub
Browse files

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


See `message:` in rule for details.
Co-authored-by: default avatarLuiz Aoqui <luiz@hashicorp.com>
No related merge requests found
Showing with 26 additions and 0 deletions
+26 -0
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.*"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment