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.
This commit is contained in:
Dmitry Vyukov 2018-06-11 16:45:05 +02:00
parent 0f0e5db62d
commit 62d1af2467

View File

@ -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 {