Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
test watchdog shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
xgess committed Jan 20, 2020
1 parent 76a1a3c commit 73f3e8f
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions keybase/platform_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func findMyParent(processes []ps.Process) (parent ps.Process, found bool) {
// running process. if such a process exists, it might kill this process during
// updating (the watchdog, which does this), so stop it first.
func (c context) stopTheWatchdog() error {
c.log.Debugf("looking for the watchdog process to stop it")
c.log.Infof("looking for the watchdog process to stop it")

fetchKeybaseProcesses := func() ([]ps.Process, error) {
path, err := Dir("Keybase")
Expand All @@ -460,37 +460,40 @@ func (c context) stopTheWatchdog() error {
}
parentProcess, found := findMyParent(kbProcesses)
if !found {
c.log.Debugf("the updater appears to be running without the watchdog which is unexpected but should be fine")
c.log.Warningf("the updater appears to be running without the watchdog which is unexpected but should be fine")
return nil
}
watchdogPid := parentProcess.Pid()
c.log.Debugf("found the updater's watchdog process at pid %d, terminating it...", watchdogPid)
c.log.Infof("found the updater's watchdog process at pid %d, terminating it...", watchdogPid)
err = process.TerminatePID(watchdogPid, 0*time.Second /*unused on windows*/, c.log)
if err != nil {
c.log.Warningf("error terminating the watchdog: %f", err.Error())
return err
}
timeOut := time.NewTimer(5 * time.Second)
checkInterval := time.NewTicker(300 * time.Millisecond)
watchdogCheckLoop:
for {
select {
case <-timeOut.C:
return fmt.Errorf("timed out trying to kill the updater's watchdog")
case <-checkInterval.C:
c.log.Debugf("checking to see if the watchdog is dead yet")
kbProcesses, err := fetchKeybaseProcesses()
if err != nil {
return err
}
for _, proc := range kbProcesses {
if proc.Pid() == parentProcess.Pid() {
// the parent process is not dead yet
continue watchdogCheckLoop
}
}
return nil
}
}
time.Sleep(5 * time.Second)
return nil
// timeOut := time.NewTimer(5 * time.Second)
// checkInterval := time.NewTicker(300 * time.Millisecond)
// watchdogCheckLoop:
// for {
// select {
// case <-timeOut.C:
// return fmt.Errorf("timed out trying to kill the updater's watchdog")
// case <-checkInterval.C:
// c.log.Infof("checking to see if the watchdog is dead yet")
// kbProcesses, err := fetchKeybaseProcesses()
// if err != nil {
// return err
// }
// for _, proc := range kbProcesses {
// if proc.Pid() == parentProcess.Pid() {
// // the parent process is not dead yet
// continue watchdogCheckLoop
// }
// }
// return nil
// }
// }
}

// copied from watchdog
Expand All @@ -501,10 +504,12 @@ func (c context) stopKeybaseProcesses() error {
return err
}

c.log.Infof("attempting to stop the watchdog")
err = c.stopTheWatchdog()
if err != nil {
c.log.Infof("Error stopping the watchdog: %s", err.Error())
}
c.log.Infof("watchdog is down, time to take down everything but the updater")
c.runKeybase(KeybaseCommandStop)
time.Sleep(time.Second)

Expand All @@ -522,7 +527,7 @@ func (c context) stopKeybaseProcesses() error {
exes = append(exes, guiExes...)
}

c.log.Infof("Terminating any existing programs we will be updating")
c.log.Infof("Terminating any existing programs we will be updating %+v", exes)
for _, program := range exes {
matcher := process.NewMatcher(program, process.PathEqual, c.log)
matcher.ExceptPID(ospid)
Expand Down

0 comments on commit 73f3e8f

Please sign in to comment.