hashicorp/nomad · error
raft_trailing_logs must be non-negative, got %d
Error message
raft_trailing_logs must be non-negative, got %d
What it means
raft_trailing_logs controls how many log entries Raft keeps after a snapshot. convertServerConfig requires the value to be at least 1; a pointer-valued config option of 0 (or negative) is rejected despite the message saying 'non-negative'.
Source
Thrown at command/agent/agent.go:253
conf.DataDir = agentConfig.Server.DataDir
}
if agentConfig.Server.RaftProtocol != 0 {
conf.RaftConfig.ProtocolVersion = raft.ProtocolVersion(agentConfig.Server.RaftProtocol)
}
if v := conf.RaftConfig.ProtocolVersion; v != 3 {
return nil, fmt.Errorf("raft_protocol must be 3 in Nomad v1.4 and later, got %d", v)
}
raftMultiplier := int(DefaultRaftMultiplier)
if agentConfig.Server.RaftMultiplier != nil && *agentConfig.Server.RaftMultiplier != 0 {
raftMultiplier = *agentConfig.Server.RaftMultiplier
if raftMultiplier < 1 || raftMultiplier > MaxRaftMultiplier {
return nil, fmt.Errorf("raft_multiplier cannot be %d. Must be between 1 and %d", *agentConfig.Server.RaftMultiplier, MaxRaftMultiplier)
}
}
if vPtr := agentConfig.Server.RaftTrailingLogs; vPtr != nil {
if *vPtr < 1 {
return nil, fmt.Errorf("raft_trailing_logs must be non-negative, got %d", *vPtr)
}
conf.RaftConfig.TrailingLogs = uint64(*vPtr)
}
if vPtr := agentConfig.Server.RaftSnapshotInterval; vPtr != nil {
dur, err := time.ParseDuration(*vPtr)
if err != nil {
return nil, err
}
if dur < 5*time.Millisecond {
return nil, fmt.Errorf("raft_snapshot_interval must be greater than 5ms, got %q", *vPtr)
}
conf.RaftConfig.SnapshotInterval = dur
}
if vPtr := agentConfig.Server.RaftSnapshotThreshold; vPtr != nil {
if *vPtr < 1 {
return nil, fmt.Errorf("raft_snapshot_threshold must be non-negative, got %d", *vPtr)View on GitHub (pinned to 482b49bf1a)
Solutions
- Set raft_trailing_logs to a positive integer (e.g. 10000, the default).
- Remove the stanza to use the Raft default.
- If intent was 'fewer retained logs', tune raft_snapshot_threshold/interval instead.
Example fix
// before
server {
raft_trailing_logs = 0
}
// after
server {
raft_trailing_logs = 10000
} Defensive patterns
Strategy: validation
Validate before calling
// Go: pre-validate
if v := cfg.Server.RaftTrailingLogs; v != nil && *v < 1 {
return fmt.Errorf("raft_trailing_logs must be >= 1")
} Try / catch
conf, err := convertServerConfig(agentCfg)
if err != nil {
if strings.Contains(err.Error(), "raft_trailing_logs") {
return fmt.Errorf("set raft_trailing_logs to a positive integer: %w", err)
}
return err
} Prevention
- Never set raft_trailing_logs to 0; omit it to use the default (10000).
- Ensure config generators emit omit/absent instead of 0 for unset ints.
- Test config rendering against a real `nomad agent` startup in CI.
When it happens
Trigger: Setting server { raft_trailing_logs = 0 } (or a negative number) then starting or reloading the agent.
Common situations: Attempting to disable trailing logs by setting 0; misreading the doc thinking 0 disables the feature; automated config generators emitting 0 for unset values.
Related errors
- raft_protocol must be 3 in Nomad v1.4 and later, got %d
- raft_multiplier cannot be %d. Must be between 1 and %d
- raft_snapshot_interval must be greater than 5ms, got %q
- raft_snapshot_threshold must be non-negative, got %d
- plugin not found
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/360cfa86c19f71a3.
Report an issue: GitHub.