Onyx-Protocol / Onyx

Onyx
https://Onyx.org
GNU Affero General Public License v3.0
1.79k stars 362 forks source link

net/raft: refactor locking #1386

Closed jbowens closed 7 years ago

jbowens commented 7 years ago

Fix a data race in TestEvictMultiple detected by go test -race. There were a few places where we locked stateMu before accessing State and a few places where we didn't.

The State implementation from database/sinkdb does its own locking, so this wasn't a real race in Chain Core, only in tests using the net/raft state implementation.

We could remove the net/raft's mutex altogether if it weren't for two things:

This change

An alternative to this approach could be to always lock stateMu before accessing State, but that would add unnecessary locking because sinkdb's State requires its own locking regardless.