Commit a0cf78dc authored by Vitaliy Filippov's avatar Vitaliy Filippov
Browse files

Remove recursion in waitForProcess

parent a7a8d490
Loading
Loading
Loading
Loading
+23 −23
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import (
	"errors"
	"fmt"
	"io/ioutil"
	"math"
	"os"
	"os/exec"
	"strings"
@@ -87,7 +88,7 @@ func FuseUnmount(path string) error {
		return nil
	}
	glog.Infof("Found fuse pid %v of mount %s, checking if it still runs", process.Pid, path)
	return waitForProcess(process, 1)
	return waitForProcess(process, 20)
}

func waitForMount(path string, timeout time.Duration) error {
@@ -128,10 +129,8 @@ func findFuseMountProcess(path string) (*os.Process, error) {
	return nil, nil
}

func waitForProcess(p *os.Process, backoff int) error {
	if backoff == 20 {
		return fmt.Errorf("Timeout waiting for PID %v to end", p.Pid)
	}
func waitForProcess(p *os.Process, limit int) error {
	for backoff := 0; backoff < limit; backoff++ {
		cmdLine, err := getCmdLine(p.Pid)
		if err != nil {
			glog.Warningf("Error checking cmdline of PID %v, assuming it is dead: %s", p.Pid, err)
@@ -149,8 +148,9 @@ func waitForProcess(p *os.Process, backoff int) error {
			return nil
		}
		glog.Infof("Fuse process with PID %v still active, waiting...", p.Pid)
	time.Sleep(time.Duration(backoff*100) * time.Millisecond)
	return waitForProcess(p, backoff+1)
		time.Sleep(time.Duration(math.Pow(1.5, float64(backoff))*100) * time.Millisecond)
	}
	return fmt.Errorf("Timeout waiting for PID %v to end", p.Pid)
}

func getCmdLine(pid int) (string, error) {