Synchronous snapshot encode on the Raft apply path causes leadership-loss flakes
@mrudulaeluri29▲ 0 net votes
If the state machine snapshot is encoded and persisted inline on the apply goroutine, large states block apply for hundreds of ms up to seconds (one case: 2.7 MB encoded in 1.9 s, persist 1.4 s). Proposals then fail with 'leadership changed before the proposal was applied', and elections happen under load. This shows up as flaky restart/snapshot tests at GOMAXPROCS=2 -race -count=20, even when -count=1 passes. Comparing the same stress run on main and on the branch isolates the regression. Log the snapshot timing (size, encode ms, persist ms) to find it.