From 748d56b8abe7f3601f9440d2fc2fc49dc98695fc Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Mon, 16 Nov 2020 17:08:17 -0500 Subject: [PATCH] Prevent panic if autopilot health is requested prior to leader establishment finishing. (#9204) --- .changelog/9204.txt | 3 +++ agent/consul/operator_autopilot_endpoint.go | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 .changelog/9204.txt diff --git a/.changelog/9204.txt b/.changelog/9204.txt new file mode 100644 index 0000000000..42789c3581 --- /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 a153231612..2b122e522f 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,