From 1810d380ab9c2786af00db592f86d83063216ed0 Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Tue, 20 Aug 2019 16:50:54 +0100 Subject: [PATCH] go-fuzz: add retrying to connect to coordinator --- go-fuzz/hub.go | 17 ++++++++++++++--- go-fuzz/main.go | 31 ++++++++++++++++--------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/go-fuzz/hub.go b/go-fuzz/hub.go index c6a787cd9..cb55b00a9 100644 --- a/go-fuzz/hub.go +++ b/go-fuzz/hub.go @@ -19,8 +19,9 @@ import ( ) const ( - syncPeriod = 3 * time.Second - syncDeadline = 100 * syncPeriod + syncPeriod = 3 * time.Second + syncDeadline = 100 * syncPeriod + connectionPollInterval = 100 * time.Millisecond minScore = 1.0 maxScore = 1000.0 @@ -123,7 +124,17 @@ func newHub(metadata MetaData) *Hub { } func (hub *Hub) connect() error { - c, err := rpc.Dial("tcp", *flagWorker) + var c *rpc.Client + var err error + + t := time.Now() + for { + c, err = rpc.Dial("tcp", *flagWorker) + if err == nil || time.Since(t) > *flagConnectionTimeout { + break + } + time.Sleep(connectionPollInterval) + } if err != nil { return err } diff --git a/go-fuzz/main.go b/go-fuzz/main.go index 15c66b224..d30f61ac6 100644 --- a/go-fuzz/main.go +++ b/go-fuzz/main.go @@ -26,21 +26,22 @@ import ( //go:generate rm go-bindata-assetfs var ( - flagWorkdir = flag.String("workdir", ".", "dir with persistent work data") - flagProcs = flag.Int("procs", runtime.NumCPU(), "parallelism level") - flagTimeout = flag.Int("timeout", 10, "test timeout, in seconds") - flagMinimize = flag.Duration("minimize", 1*time.Minute, "time limit for input minimization") - flagCoordinator = flag.String("coordinator", "", "coordinator mode (value is coordinator address)") - flagWorker = flag.String("worker", "", "worker mode (value is coordinator address)") - flagBin = flag.String("bin", "", "test binary built with go-fuzz-build") - flagFunc = flag.String("func", "", "function to fuzz") - flagDumpCover = flag.Bool("dumpcover", false, "dump coverage profile into workdir") - flagDup = flag.Bool("dup", false, "collect duplicate crashers") - flagTestOutput = flag.Bool("testoutput", false, "print test binary output to stdout (for debugging only)") - flagCoverCounters = flag.Bool("covercounters", true, "use coverage hit counters") - flagSonar = flag.Bool("sonar", true, "use sonar hints") - flagV = flag.Int("v", 0, "verbosity level") - flagHTTP = flag.String("http", "", "HTTP server listen address (coordinator mode only)") + flagWorkdir = flag.String("workdir", ".", "dir with persistent work data") + flagProcs = flag.Int("procs", runtime.NumCPU(), "parallelism level") + flagTimeout = flag.Int("timeout", 10, "test timeout, in seconds") + flagMinimize = flag.Duration("minimize", 1*time.Minute, "time limit for input minimization") + flagCoordinator = flag.String("coordinator", "", "coordinator mode (value is coordinator address)") + flagWorker = flag.String("worker", "", "worker mode (value is coordinator address)") + flagConnectionTimeout = flag.Duration("connectiontimeout", 1*time.Minute, "time limit for worker to try to connect coordinator") + flagBin = flag.String("bin", "", "test binary built with go-fuzz-build") + flagFunc = flag.String("func", "", "function to fuzz") + flagDumpCover = flag.Bool("dumpcover", false, "dump coverage profile into workdir") + flagDup = flag.Bool("dup", false, "collect duplicate crashers") + flagTestOutput = flag.Bool("testoutput", false, "print test binary output to stdout (for debugging only)") + flagCoverCounters = flag.Bool("covercounters", true, "use coverage hit counters") + flagSonar = flag.Bool("sonar", true, "use sonar hints") + flagV = flag.Int("v", 0, "verbosity level") + flagHTTP = flag.String("http", "", "HTTP server listen address (coordinator mode only)") shutdown uint32 shutdownC = make(chan struct{})