aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/instance
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-06-11 16:45:05 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-06-11 16:47:12 +0200
commit62d1af2467768d46623d446efaaf2f2cb6e8350e (patch)
treecf8cce2e4a77f7ab4d7c7fc0aab81559157295b3 /pkg/instance
parent0f0e5db62d485e07105f5401349382692271cf31 (diff)
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.
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/instance.go11
1 files changed, 6 insertions, 5 deletions
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 {