From 15ea34f49b8cd48d235c88a373bbd476a00965d8 Mon Sep 17 00:00:00 2001 From: Rene Kaufmann Date: Mon, 14 Nov 2016 15:25:21 +0100 Subject: [PATCH] removed useless if block --- executor/executor.go | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/executor/executor.go b/executor/executor.go index 1273d3b4..a2a26f4a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -153,37 +153,35 @@ func (e *Executor) CancelOnExit(ctx context.Context, cancel context.CancelFunc) e.childLock.RUnlock() for { - if notNil { - select { - case <-ctx.Done(): - return - case code := <-exitChan: - // wait a little bit to give the process time to start - // in case of a reload - time.Sleep(1 * time.Second) - e.childLock.RLock() - nexitChan := e.child.ExitCh() - // the exitChan has changed which means the process was reloaded - // don't exit in this case - if nexitChan != exitChan { - exitChan = nexitChan + select { + case <-ctx.Done(): + return + case code := <-exitChan: + // wait a little bit to give the process time to start + // in case of a reload + time.Sleep(1 * time.Second) + e.childLock.RLock() + nexitChan := e.child.ExitCh() + // the exitChan has changed which means the process was reloaded + // don't exit in this case + if nexitChan != exitChan { + exitChan = nexitChan + e.childLock.RUnlock() + continue + } + // the process exited - stop + e.childLock.RUnlock() + if code != 0 { + e.logger.Error(fmt.Sprintf("(child) process exited unexpectedly with code: %d", code)) + if e.restartOnFailure { + e.restartChild() + e.childLock.RLock() + exitChan = e.child.ExitCh() e.childLock.RUnlock() continue } - // the process exited - stop - e.childLock.RUnlock() - if code != 0 { - e.logger.Error(fmt.Sprintf("(child) process exited unexpectedly with code: %d", code)) - if e.restartOnFailure { - e.restartChild() - e.childLock.RLock() - exitChan = e.child.ExitCh() - e.childLock.RUnlock() - continue - } - } - cancel() } + cancel() } } }