GetConfiguration().Index() returns zero after bootstrap, preventing version-guarded membership updates
Problem
Raft.GetConfiguration().Index() returns 0 for an initialized cluster even though Raft internally has a nonzero configuration index. This prevents a caller from using the returned configuration and index for the documented prevIndex guard on membership changes. Passing the returned zero instead disables that guard.
This is a configuration-readback problem, not a claim that elections, replication, or Raft's internal membership-transition rules are broken.
Environment
- Reproduced on the latest release,
v1.8.0(0f543c0). - The same read path is present on
mainat871f108efbeb26c06636c4b388e18fc698de6f62. - Go 1.26.8, darwin/arm64.
- In-memory stores and transport; no external services or network listeners.
Minimal reproduction
In a checkout of v1.8.0, save the following as configuration_index_repro_test.go and run:
go test -count=1 -timeout=30s -run '^TestConfigurationIndexAfterBootstrap$' .package raft_test
import (
"testing"
"github.com/hashicorp/raft"
)
func TestConfigurationIndexAfterBootstrap(t *testing.T) {
cfg := raft.DefaultConfig()
cfg.LocalID = "server-1"
addr, transport := raft.NewInmemTransport("server-1")
t.Cleanup(func() {
if err := transport.Close(); err != nil {
t.Error(err)
}
})
store := raft.NewInmemStore()
snapshots := raft.NewInmemSnapshotStore()
initial := raft.Configuration{Servers: []raft.Server{{
ID: cfg.LocalID, Address: addr, Suffrage: raft.Voter,
}}}
if err := raft.BootstrapCluster(cfg, store, store, snapshots, transport, initial); err != nil {
t.Fatal(err)
}
r, err := raft.NewRaft(cfg, &raft.MockFSM{}, store, store, snapshots, transport)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := r.Shutdown().Error(); err != nil {
t.Error(err)
}
})
future := r.GetConfiguration()
if err := future.Error(); err != nil {
t.Fatal(err)
}
if len(future.Configuration().Servers) != 1 {
t.Fatalf("unexpected configuration: %+v", future.Configuration())
}
if index := future.Index(); index != 1 {
t.Fatalf("configuration index = %d; want bootstrap configuration index 1", index)
}
}Expected: one server and configuration index 1, matching the bootstrap configuration.
Actual:
configuration index = 0; want bootstrap configuration index 1The startup log reports initial configuration: index=1, so the configuration index exists internally.
Source analysis
setLatestConfigurationstores both the configuration and index in the main-loop state, but publishes only the configuration to the atomic read cache.GetConfigurationconstructs aconfigurationsvalue with onlylatestpopulated.configurationsFuture.Indexreturns the resulting zero-valuedlatestIndex.AddVoterdocuments the nonzeroprevIndexguard;nextConfigurationintentionally skips it when zero is supplied.
This readback change appears to originate in #379, which moved public configuration reads off the main loop. The existing ConfigurationFuture interface still includes Index().
Proposed scope
Publish the latest configuration and its corresponding index together through the existing atomic cache. Preserve zero for an uninitialized instance and preserve the optional zero-prevIndex mutation behavior. No public API signature, wire format, or persisted-state format change is needed.
Regression coverage should check configuration/index pairing, concurrent reads, stale-version rejection using the public readback, and snapshot restoration.
AI assistance: OpenAI Codex was used for investigation and preparation of this report. The reproduction was executed locally against the unmodified release.
Source: hashicorp/raft