diff --git a/.changelog/9204.txt b/.changelog/9204.txt new file mode 100644 index 000000000..42789c358 --- /dev/null +++ b/.changelog/9204.txt @@ -0,0 +1,3 @@ +```release-note:bug +autopilot: Prevent panic when requesting the autopilot health immediately after a leader is elected. +``` diff --git a/agent/consul/operator_autopilot_endpoint.go b/agent/consul/operator_autopilot_endpoint.go index a15323161..2b122e522 100644 --- a/agent/consul/operator_autopilot_endpoint.go +++ b/agent/consul/operator_autopilot_endpoint.go @@ -100,6 +100,12 @@ func (op *Operator) ServerHealth(args *structs.DCSpecificRequest, reply *structs state := op.srv.autopilot.GetState() + if state == nil { + // this behavior seems odd but its functionally equivalent to 1.8.5 where if + // autopilot didn't have a health reply yet it would just return no error + return nil + } + health := structs.AutopilotHealthReply{ Healthy: state.Healthy, FailureTolerance: state.FailureTolerance,