Skipped InstallFullSnapshot hangs after leader change or follower restart

perfloop-oss/openraft · Missed notification

https://perfloop.ai/t/oss/case_0hjtvnp33b

Verdict

VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-25 · pull request opened as databendlabs/openraft#2518

What happened: The check fails before this change and passes with it.

Hypothesis

When a follower receives an `InstallFullSnapshot` request whose last log ID is at or before the follower's `local_committed`, it skips installing the snapshot and waits on a log-flush condition pairing the current leader vote with the snapshot's last log ID. However, it never schedules an I/O progress update to advance the flushed log progress to that pair. Whenever the follower has not already accepted a log I/O for the current leader vote at or beyond that log ID—such as after adopting a newer leader vote or after restarting from durable storage—no command ever satisfies the condition, so the snapshot RPC hangs indefinitely and sits at the head of the FIFO pending-response queue.

In `FollowingHandler::install_full_snapshot` (`openraft/src/engine/handler/following_handler/mod.rs:273-357`), the early-return branch at lines 279-293 checks `snap_last_log_id.as_ref() <= self.state.local_committed()` and returns `Condition::IOFlushed { io_id: LogIOId::new(self.leader_vote.to_committed(), Some(last)).to_io_id() }` without calling `self.state.accept_log_io` or emitting `Command::UpdateIOProgress`. `Engine::handle_install_full_snapshot` (`openraft/src/engine/engine_impl.rs:724-754`) passes that condition directly to `Command::Respond`, which `RaftCore` postpones into `EngineOutput.pending_responds.on_log_io` (`openraft/src/engine/pending_responds.rs:15-50`). Because `IOId` orders by `(vote, last_log_id)`, both `Command::SaveVote` (when accepting a newer committed vote) and `IOState::new` on node restart (`openraft/src/raft_state/io_state.rs:202`) leave `log_progress.flushed()` at `LogIOId(leader_vote, None)`, which is strictly less than `LogIOId(leader_vote, Some(last))`. No subsequent command advances `log_progress` unless an unrelated append at or beyond `last` arrives, and the leader's snapshot replication stream blocks waiting for this RPC response and retries the same snapshot on timeout.

This regression was introduced in commit `18ee3d1` (`fix: openraft: answer a skipped snapshot only once its logs are flushed`); an upstream check of open GitHub PRs touching `openraft/src/engine/handler/following_handler/mod.rs` returned none. A bounded exhaustive search across 18 combinations of `{restarted: false/true} x {same vote / newer vote} x {snap_last_log_id: None / index 0 / index 1} x {hold_flush: false/true}` (`cargo test -p tests --test prop_skipped_snapshot_responds -- --nocapture`) failed on all 8 cases where `snap_last_log_id` was `Some(...)` and either the vote was newer or the node restarted.

The attached deterministic replay (`cargo test -p tests --test replay_skipped_snapshot_hang -- --nocapture`) reproduces the hang on the base revision: `raft.append_entries` durably commits and flushes logs 0..=1 under vote `(1, 0, C)`, and `raft.install_full_snapshot` with vote `(2, 2, C)` and `last_log_id = Some((1, 0, 1))` times out after 1s (`Elapsed(())`). The Case proof should confirm that all 18 search cases, the deterministic replay, and existing tests including `t35_skipped_snapshot_waits_for_flush` pass while preserving durability waiting when an earlier append for the same vote is still unflushed, and should also verify whether `Engine::handle_install_full_snapshot` unit tests in `openraft/src/engine/tests/install_full_snapshot_test.rs` and `openraft/src/engine/handler/following_handler/install_snapshot_test.rs` need updated expected command sequences.

Change to test: In `FollowingHandler::install_full_snapshot`, when skipping a snapshot with a `Some(last)` log ID because `snap_last_log_id <= local_committed`, record `to_submit = LogIOId::new(self.leader_vote.to_committed(), Some(last)).to_io_id()` via `self.state.accept_log_io(to_submit.clone())` and, if `Some(&to_submit) > prev_accepted.as_ref()`, push `Command::UpdateIOProgress { when: prev_accepted.map(|x| Condition::IOFlushed { io_id: x }), io_id: to_submit.clone() }` before returning `Condition::IOFlushed { io_id: to_submit }`. This mirrors `FollowingHandler::append_entries` when no new log entries need writing, so prior in-flight IOs still flush first while already-flushed logs and vote changes advance `log_progress` and wake the response.

Where it lives

perfloop-oss/openraft · openraft/src/raft/mod.rs

Evidence

The check fails before this change and passes with it: `With ticking and elections disabled and serialized durable storage, a follower with committed logs 0..=1 completes skipped InstallFullSnapshot requests without another append after leader change or restart in the 18-case matrix and the gRPC leader-change replay, while a nonempty same-vote snapshot waits for a held preceding append flush.`

Checks: 8 of 8 passed. Verification: no defect found.

Timeline