From 62d1af2467768d46623d446efaaf2f2cb6e8350e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 11 Jun 2018 16:45:05 +0200 Subject: pkg/instance: more robust instance testing Strictly saying, we may not get the connection when the fuzzer process exits. The accepting goroutine may have not been scheduled yet. For the connection for up to 10 seconds. --- pkg/instance/instance.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'pkg/instance') diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index 98893a590..9a1b95dae 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -12,7 +12,6 @@ import ( "os" "path/filepath" "strings" - "sync/atomic" "time" "github.com/google/syzkaller/pkg/csource" @@ -215,13 +214,13 @@ func (inst *inst) testInstance() error { return fmt.Errorf("failed to open listening socket: %v", err) } defer ln.Close() - var gotConn uint32 + acceptErr := make(chan error, 1) go func() { conn, err := ln.Accept() if err == nil { conn.Close() - atomic.StoreUint32(&gotConn, 1) } + acceptErr <- err }() fwdAddr, err := inst.vm.Forward(ln.Addr().(*net.TCPAddr).Port) if err != nil { @@ -252,10 +251,12 @@ func (inst *inst) testInstance() error { Report: rep, } } - if atomic.LoadUint32(&gotConn) == 0 { + select { + case err := <-acceptErr: + return err + case <-time.After(10 * time.Second): return fmt.Errorf("test machine failed to connect to host") } - return nil } func (inst *inst) testRepro() error { -- cgit mrf-deployment