{"record":{"id":"ba32f96fe4eb4d4a","repo":"hashicorp/nomad","slug":"error-parsing-server-s-last-log-index-value-s","errorCode":null,"errorMessage":"error parsing server's last_log_index value: %s","messagePattern":"error parsing server's last_log_index value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/status_endpoint.go","lineNumber":138,"sourceCode":"\t\tMembers:      members,\n\t}\n\treturn nil\n}\n\n// RaftStats is used by Autopilot to query the raft stats of the local server.\nfunc (s *Status) RaftStats(args *structs.GenericRequest, reply *structs.RaftStats) error {\n\t// note: we're intentionally throwing away any auth error here and only\n\t// authenticate so that we can measure rate metrics\n\ts.srv.Authenticate(s.ctx, args)\n\ts.srv.MeasureRPCRate(\"status\", structs.RateMetricRead, args)\n\n\tstats := s.srv.raft.Stats()\n\n\tvar err error\n\treply.LastContact = stats[\"last_contact\"]\n\treply.LastIndex, err = strconv.ParseUint(stats[\"last_log_index\"], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error parsing server's last_log_index value: %s\", err)\n\t}\n\treply.LastTerm, err = strconv.ParseUint(stats[\"last_log_term\"], 10, 64)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error parsing server's last_log_term value: %s\", err)\n\t}\n\n\treturn nil\n}\n\n// HasNodeConn returns whether the server has a connection to the requested\n// Node.\nfunc (s *Status) HasNodeConn(args *structs.NodeSpecificRequest, reply *structs.NodeConnQueryResponse) error {\n\t// note: we're intentionally throwing away any auth error here and only\n\t// authenticate so that we can measure rate metrics\n\ts.srv.Authenticate(s.ctx, args)\n\ts.srv.MeasureRPCRate(\"status\", structs.RateMetricRead, args)\n\n\t// Validate the args","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/status_endpoint.go#L120-L156","documentation":"The Status().RaftStats endpoint reads the local Raft stats map and parses stats[\"last_log_index\"] with strconv.ParseUint. This error means the value present in the Raft stats map could not be parsed as an unsigned 64-bit integer — the hashicorp/raft library contract is broken (empty string, or unexpected format from an incompatible raft version).","triggerScenarios":"Calling nomad operator raft / Status().RaftStats (via client RPC 'Status.RaftStats' from fetch) on a server whose raft.Stats() returns a last_log_index that is empty or non-numeric.","commonSituations":"Version-skew: a Nomad server binary built against a different hashicorp/raft version whose stats keys differ; raft not fully initialized when stats are polled; instrumentation/patching altering stats output.","solutions":["Check the wrapped '%s' value — strconv messages reveal whether the string was empty or malformed.","Ensure client and server Nomad versions are compatible (upgrade clients to match servers).","Retry after the server finishes startup/election; raft stats may be transiently unpopulated.","Verify no patched/instrumented raft library is in the server build (go version -m nomad)."],"exampleFix":"// before\nstats, err := agent.Status().RaftStats()\n// after\nstats, err := agent.Status().RaftStats()\nif err != nil && strings.Contains(err.Error(), \"last_log_index\") {\n  logger.Warn(\"raft stats not parseable yet; server may still be initializing\", \"err\", err)\n  time.Sleep(2 * time.Second)\n  stats, err = agent.Status().RaftStats()\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"func isRaftStatsParseError(err error) bool { return err != nil && strings.Contains(err.Error(), \"last_log_index\") }","tryCatchPattern":"stats, err := srv.Status().RaftStats()\nif isRaftStatsParseError(err) {\n  time.Sleep(retryDelay) // server may still be initializing\n  stats, err = srv.Status().RaftStats()\n  if err != nil { return fmt.Errorf(\"raft stats unavailable: %w\", err) }\n}","preventionTips":["Keep Nomad client and server versions aligned.","Only poll raft stats on servers that have completed startup/leader election.","Avoid patched/instrumented hashicorp/raft builds that change stats keys."],"tags":["nomad","raft","parsing","rpc"],"backgroundTag":"raft-stats-parse-error","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}