Forward follower's append_entries_reply when it already has the snapshot#641
Merged
Conversation
A follower whose last_applied is at or ahead of an incoming snapshot's index rejects the install_snapshot_rpc with an append_entries_reply rather than an install_snapshot_result. The snapshot sender treated this as fatal (exit(unexpected_install_snapshot_result)), so the reply never reached the leader and next_index was never corrected — the leader re-sent the same snapshot indefinitely, until the next election. The sender now forwards that reply to the leader and exits normally. The leader's existing success = false handler advances next_index to the position the follower indicated, breaking the loop. Adds ra_SUITE test snapshot_installation_target_already_has_snapshot.
There was a problem hiding this comment.
Pull request overview
Fixes a Raft snapshot retry loop where a follower that already has (or is ahead of) an incoming snapshot rejects install_snapshot_rpc with an append_entries_reply, and the snapshot-sender previously treated that as fatal—preventing the leader from correcting next_index.
Changes:
- Forward
#append_entries_reply{}responses frominstall_snapshot_rpcback to the leader and terminate the snapshot-sender normally. - Add regression test
snapshot_installation_target_already_has_snapshotto ensure the forwarded reply reaches the leader and the cluster converges.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ra_server_proc.erl |
Forward append_entries_reply to leader during snapshot send to avoid fatal exit and unblock next_index correction. |
test/ra_SUITE.erl |
Adds regression coverage for the “target already has snapshot” scenario using meck to force the follower response and verify forwarding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mkuratczyk
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A follower whose last_applied is at or ahead of an incoming snapshot's index rejects the install_snapshot_rpc with an append_entries_reply rather than an install_snapshot_result. The snapshot sender treated this as fatal (exit(unexpected_install_snapshot_result)), so the reply never reached the leader and next_index was never corrected — the leader re-sent the same snapshot indefinitely, until the next election.
The sender now forwards that reply to the leader and exits normally. The leader's existing success = false handler advances next_index to the position the follower indicated, breaking the loop.
Adds ra_SUITE test snapshot_installation_target_already_has_snapshot.