From d89687d014b9448aa8da8d5f1bca8f34bd937f03 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 13 Apr 2020 10:32:34 -0400 Subject: [PATCH] agent: shutdown agent http server last Shutdown http server last, after nomad client/server components terminate. Before this change, if the agent is taking an unexpectedly long time to shutdown, the operator cannot query the http server directly: they cannot access agent specific http endpoints and need to query another agent about the troublesome agent. Unexpectedly long shutdown can happen in normal cases, e.g. a client might hung is if one of the allocs it is running has a long shutdown_delay. Here, we switch to ensuring that the http server is shutdown last. I believe this doesn't require extra care in agent shutting down logic while operators may be able to submit write http requests. We already need to cope with operators submiting these http requests to another agent or by servers updating the client allocations. --- command/agent/command.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index a7ab4424b..bb1a2cda2 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -640,10 +640,12 @@ func (c *Command) Run(args []string) int { logGate.Flush() return 1 } - defer c.agent.Shutdown() - // Shutdown the HTTP server at the end defer func() { + c.agent.Shutdown() + + // Shutdown the http server at the end, to ease debugging if + // the agent takes long to shutdown if c.httpServer != nil { c.httpServer.Shutdown() }