docker: Terminate dockerlogger

Previously, we did not attempt to stop Docker Logger processes until
DestroyTask, which means that under many circumstances, we will never
successfully close the plugin client.

This commit terminates the plugin process when `run` terminates, or when
`DestroyTask` is called.

Steps to repro:

```
$ nomad agent -dev
$ nomad init
$ nomad run example.nomad
$ nomad stop example
$ ps aux | grep nomad # See docker logger process running
$ signal the dev agent
$ ps aux | grep nomad # See docker logger process running
```
This commit is contained in:
Danielle Tomlinson
2019-01-14 12:31:30 +01:00
parent 109c5ef650
commit f9a4594095
2 changed files with 10 additions and 7 deletions

View File

@@ -1019,17 +1019,10 @@ func (d *Driver) DestroyTask(taskID string, force bool) error {
return fmt.Errorf("must call StopTask for the given task before Destroy or set force to true")
}
defer h.dloggerPluginClient.Kill()
if err := h.client.StopContainer(h.containerID, 0); err != nil {
h.logger.Warn("failed to stop container during destroy", "error", err)
}
if err := h.dlogger.Stop(); err != nil {
h.logger.Error("failed to stop docker logger process during destroy",
"error", err, "logger_pid", h.dloggerPluginClient.ReattachConfig().Pid)
}
if err := d.cleanupImage(h); err != nil {
h.logger.Error("failed to cleanup image after destroying container",
"error", err)

View File

@@ -156,7 +156,17 @@ func (h *taskHandle) Kill(killTimeout time.Duration, signal os.Signal) error {
return nil
}
func (h *taskHandle) shutdownLogger() {
if err := h.dlogger.Stop(); err != nil {
h.logger.Error("failed to stop docker logger process during StopTask",
"error", err, "logger_pid", h.dloggerPluginClient.ReattachConfig().Pid)
}
h.dloggerPluginClient.Kill()
}
func (h *taskHandle) run() {
defer h.shutdownLogger()
exitCode, werr := h.waitClient.WaitContainer(h.containerID)
if werr != nil {
h.logger.Error("failed to wait for container; already terminated")