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

the leaderElected event seems to be triggered on each heartbeat by all followers #14

Open
bagrounds opened this issue Mar 4, 2017 · 2 comments
Labels

Comments

@bagrounds
Copy link

I put together a little demo here

If I add a console.log statement in the leaderElected event handler, all followers spam that log statement even if the leader has not changed.

Perhaps there should be an event for the heartbeat, and a different event for a successful leader election.

@ben-ng
Copy link
Owner

ben-ng commented Mar 5, 2017

Urgh, this is definitely a bug. I think the bug is here. That emit should only happen if the term is greater than the current term, not greater than or equal to, which is what it currently is.

Wanna give fixing it a shot?

@ben-ng ben-ng added the bug label Mar 5, 2017
@bagrounds
Copy link
Author

If I change that from >= to >, then

  1. the spamming stops
  2. but now followers don't seem to emit the leaderElected event at all (not even once)
  3. and a bunch of tests break

test output:
change-gte-to-gt-test-output-1488771562.txt

I tried a few variations, but was unable to get the followers to emit leaderElected exactly once.

I also noticed that there are 2 other places in the code where leaderElected event can be emitted (line 429 and line 544 in addition to line 570 that you pointed out above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants