guille / RaftCore

An implementation of the Raft algorithm using .NET Core
MIT License
67 stars 22 forks source link

Thread Safety #7

Open xucito opened 5 years ago

xucito commented 5 years ago

Don't know if you are still working on this, but I looked at your implementation and found some issues - just a FYI.

A lot of the operations in your implementation are not thread safe.

An example of this is, your heartbeats interval can exceed the time it takes to complete a heartbeat, as a result you can have two "AppendEntries" running concurrently, this causes issues particularly when both threads reach

toApply.ForEach(x => StateMachine.Apply(x.Command));

applying your logs twice.

You should have dedicated threads that loop this check and log application.

guille commented 5 years ago

Yep, it's definitely an issue. I don't really have the time to keep improving RaftCore but if anyone wants to take a stab at it I'll review and merge the PR.

Thanks!