diff options
author | Sebastiaan van Stijn <thaJeztah@users.noreply.github.com> | 2019-06-07 13:16:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-07 13:16:46 +0200 |
commit | c85fe2d2242fbd6f9e4ea5cdef75d24945018ede (patch) | |
tree | 93d73f2fa9c4430e546d0612f6cc8b3684a4491e /plugin | |
parent | 1d5748d975333eb90c3c438bd1c983aa004e31d9 (diff) | |
parent | eaad3ee3cf0d69aa22d1d1eca10c4ae46ff92f6e (diff) |
Merge pull request #38522 from cpuguy83/fix_timers
Make sure timers are stopped after use.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/manager_linux.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/plugin/manager_linux.go b/plugin/manager_linux.go index 86ada8d02f..23fa462865 100644 --- a/plugin/manager_linux.go +++ b/plugin/manager_linux.go @@ -146,6 +146,8 @@ func (pm *Manager) restore(p *v2.Plugin, c *controller) error { return nil } +const shutdownTimeout = 10 * time.Second + func shutdownPlugin(p *v2.Plugin, ec chan bool, executor Executor) { pluginID := p.GetID() @@ -153,19 +155,26 @@ func shutdownPlugin(p *v2.Plugin, ec chan bool, executor Executor) { if err != nil { logrus.Errorf("Sending SIGTERM to plugin failed with error: %v", err) } else { + + timeout := time.NewTimer(shutdownTimeout) + defer timeout.Stop() + select { case <-ec: logrus.Debug("Clean shutdown of plugin") - case <-time.After(time.Second * 10): + case <-timeout.C: logrus.Debug("Force shutdown plugin") if err := executor.Signal(pluginID, int(unix.SIGKILL)); err != nil { logrus.Errorf("Sending SIGKILL to plugin failed with error: %v", err) } + + timeout.Reset(shutdownTimeout) + select { case <-ec: logrus.Debug("SIGKILL plugin shutdown") - case <-time.After(time.Second * 10): - logrus.Debug("Force shutdown plugin FAILED") + case <-timeout.C: + logrus.WithField("plugin", p.Name).Warn("Force shutdown plugin FAILED") } } } |