Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 12, 2022
Merged

Conversation

schmichael
Copy link
Member

See message: in rule for details.

This catches a few uses that should be cleaned up:

$ semgrep scan -c .semgrep/fsm_time.yml nomad
... 

nomad/fsm.go
     semgrep.no-time-in-fsm
        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.

        568┆ Launch:    time.Now(),


  nomad/state/state_store.go
     semgrep.no-time-in-fsm
        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.

       4450┆ status.RequireProgressBy = time.Now().Add(status.ProgressDeadline)
          ⋮┆----------------------------------------
       5866┆ iter = memdb.NewFilterIterator(iter, expiredOneTimeTokenFilter(time.Now()))
          ⋮┆----------------------------------------
       6651┆ rootKeyMeta.CreateTime = time.Now()

See `message:` in rule for details.
Copy link
Contributor

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion, but LGTM as-is as well.

Currently semgrep only runs on code changes in a PR, so the existing cases would not be a problem 👍

.semgrep/fsm_time.yml Outdated Show resolved Hide resolved
Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
@tgross
Copy link
Member

tgross commented Jul 13, 2022

I've fixed the keyring and OTT cases in #13737 and #13733

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants