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.
This commit is contained in:
Mahmood Ali
2020-04-13 10:32:34 -04:00
parent cafdcc9216
commit d89687d014

View File

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