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()