From 9bd3a7c0297fdb93deb846070c85ac23da0a20e8 Mon Sep 17 00:00:00 2001 From: milindchawre Date: Thu, 2 Feb 2017 18:19:17 +0000 Subject: [PATCH] Adding support for docker max restart time Signed-off-by: milindchawre --- restartmanager/restartmanager.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/restartmanager/restartmanager.go b/restartmanager/restartmanager.go index 9d219d9d54..ec3b1cc240 100644 --- a/restartmanager/restartmanager.go +++ b/restartmanager/restartmanager.go @@ -12,6 +12,7 @@ import ( const ( backoffMultiplier = 2 defaultTimeout = 100 * time.Millisecond + maxRestartTimeout = 1 * time.Minute ) // ErrRestartCanceled is returned when the restart manager has been @@ -70,11 +71,15 @@ func (rm *restartManager) ShouldRestart(exitCode uint32, hasBeenManuallyStopped if executionDuration.Seconds() >= 10 { rm.timeout = 0 } - if rm.timeout == 0 { + switch { + case rm.timeout == 0: rm.timeout = defaultTimeout - } else { + case rm.timeout < maxRestartTimeout: rm.timeout *= backoffMultiplier } + if rm.timeout > maxRestartTimeout { + rm.timeout = maxRestartTimeout + } var restart bool switch {