Skip to content

Conversation

@neilalexander
Copy link
Member

The runAsCandidate and runAsFollower goroutines both try to drain the append entry response and proposal queues if they are still populated from the previous leadership, but we might be blocked in runAsCandidate or runAsFollower while switching to leader waiting for the state change to complete and accidentally drain incoming proposals.

Signed-off-by: Neil Twigg neil@nats.io

@neilalexander neilalexander requested a review from a team as a code owner January 6, 2026 17:55
The `runAsCandidate` and `runAsFollower` goroutines both try to drain
the append entry response and proposal queues if they are still populated
from the previous leadership, but we might be blocked in `runAsCandidate`
or `runAsFollower` while switching to leader waiting for the state change
to complete and accidentally drain incoming proposals.

Signed-off-by: Neil Twigg <neil@nats.io>
Copy link
Member

@MauriceVanVeen MauriceVanVeen left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

Be good to have a test that shows what this is fixing or accommodating for.

Copy link
Contributor

@sciascid sciascid left a comment

Choose a reason for hiding this comment

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

How about moving these calls to drain before the loop?

n.votes.popOne()
case <-n.resp.ch:
// Ignore append entry responses received from before the state change.
n.resp.drain()
Copy link
Contributor

Choose a reason for hiding this comment

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

How about moving the calls to drain before the loop?
Then we just need to make sure we push into the queues only if the node if the process is the leader. This is already checked for proposals, but appears to be easy to add for appendEntry responses.
Doing so we would avoid the need to re-notify...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants