Skip to content

Commit

Permalink
Cherry pick : Reset session status on tether init (#6202)
Browse files Browse the repository at this point in the history
We were not reinitializing session status on out-of-band power
operations, meaning we hit a filter in the launch logic that skipped
launching the container process.

Additional tests to follow
  • Loading branch information
Anchal Agrawal authored and mdubya66 committed Sep 1, 2017
1 parent e4e9eb7 commit ae9b227
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions lib/tether/tether.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ func (t *tether) initializeSessions() error {
session.ClearToLaunch = make(chan struct{})
}

// this will need altering if tether should be capable of being restarted itself
session.Started = ""
session.StopTime = 0

session.wait = &sync.WaitGroup{}
session.extraconfigKey = name
err := t.loggingLocked(session)
Expand Down Expand Up @@ -420,37 +424,39 @@ func (t *tether) processSessions() error {

// process the sessions and launch if needed
for id, session := range m.sessions {
session.Lock()
func() {
session.Lock()
defer session.Unlock()

log.Debugf("Processing config for session %s", id)
var proc = session.Cmd.Process
log.Debugf("Processing config for session: %s", id)
var proc = session.Cmd.Process

// check if session is alive and well
if proc != nil && proc.Signal(syscall.Signal(0)) == nil {
log.Debugf("Process for session %s is running (pid: %d)", id, proc.Pid)
if !session.Active {
// stop process - for now this doesn't do any staged levels of aggression
log.Infof("Running session %s has been deactivated (pid: %d)", id, proc.Pid)
// check if session is alive and well
if proc != nil && proc.Signal(syscall.Signal(0)) == nil {
log.Debugf("Process for session %s is running (pid: %d)", id, proc.Pid)
if !session.Active {
// stop process - for now this doesn't do any staged levels of aggression
log.Infof("Running session %s has been deactivated (pid: %d)", id, proc.Pid)

killHelper(session)
killHelper(session)
}

return
}

session.Unlock()
continue
}
// if we're not activating this session and it's not running, then skip
if !session.Active {
log.Debugf("Skipping inactive session: %s", id)
return
}

// if we're not activating this session and it's not running, then skip
if !session.Active {
log.Debugf("Skipping inactive session %s", id)
session.Unlock()
continue
}
priorLaunch := proc != nil || session.Started != ""
if priorLaunch && !session.Restart {
log.Debugf("Skipping non-restartable exited or failed session: %s", id)
return
}

// check if session has never been started or is configured for restart
// if proc is nil, but Started is set then it could be a launch failure
if (proc == nil && session.Started == "") || session.Restart {
// if we've never been started
if proc == nil && session.Started == "" {
if !priorLaunch {
log.Infof("Launching process for session %s", id)
log.Debugf("Launch failures are fatal: %t", m.fatal)
} else {
Expand All @@ -473,9 +479,7 @@ func (t *tether) processSessions() error {
fatal: m.fatal,
}
}(session)

}
session.Unlock()
}()
}
}

Expand Down

0 comments on commit ae9b227

Please sign in to comment.