From 0adbe4cf413682fea9c8c41abb0adc5fba1a6775 Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Mon, 3 Feb 2020 10:27:29 -0500 Subject: [PATCH] agent Profile req nil check s.agent.Server() --- command/agent/agent_endpoint.go | 8 ++++++-- command/agent/agent_endpoint_test.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 416f403b5cb3..1ed998077569 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -396,8 +396,12 @@ func (s *HTTPServer) agentPprof(reqType pprof.ReqType, resp http.ResponseWriter, rpcErr = s.agent.Server().RPC("Agent.Profile", &args, &reply) } } else { - // No node id target server - rpcErr = s.agent.Server().RPC("Agent.Profile", &args, &reply) + // No NodeID, profile current server/client + if srv := s.agent.Server(); srv != nil { + rpcErr = srv.RPC("Agent.Profile", &args, &reply) + } else { + rpcErr = s.agent.Client().RPC("Agent.Profile", &args, &reply) + } } if rpcErr != nil { diff --git a/command/agent/agent_endpoint_test.go b/command/agent/agent_endpoint_test.go index 32acc6698f61..163c5ecd256c 100644 --- a/command/agent/agent_endpoint_test.go +++ b/command/agent/agent_endpoint_test.go @@ -521,11 +521,17 @@ func TestAgent_PprofRequest(t *testing.T) { addNodeID bool addServerID bool expectedErr string + nilServer bool }{ { - desc: "cmdline local request", + desc: "cmdline local server request", url: "/v1/agent/pprof/cmdline", }, + { + desc: "cmdline local node request", + url: "/v1/agent/pprof/cmdline", + nilServer: true, + }, { desc: "cmdline node request", url: "/v1/agent/pprof/cmdline", @@ -577,6 +583,10 @@ func TestAgent_PprofRequest(t *testing.T) { url = url + "?server_id=" + s.server.LocalMember().Name } + if tc.nilServer { + s.Agent.server = nil + } + req, err := http.NewRequest("GET", url, nil) require.Nil(t, err) respW := httptest.NewRecorder()