Timeout the shim on Accept and Wait.

https://build.chromium.org/p/client.boringssl/builders/linux_fips_rel/builds/115
appears to have failed because we were hanging on Accept() forever.
Impose a timeout on that and waiting for the process to return so we at
least can see what stdout/stderr was received so far.

Change-Id: Ief7f7759d02a3fbfc504d2f214b742672b0fe9e6
Reviewed-on: https://boringssl-review.googlesource.com/16005
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
diff --git a/ssl/test/runner/runner.go b/ssl/test/runner/runner.go
index 55e22b6..0b66106 100644
--- a/ssl/test/runner/runner.go
+++ b/ssl/test/runner/runner.go
@@ -844,13 +844,14 @@
 
 // accept accepts a connection from listener, unless waitChan signals a process
 // exit first.
-func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
+func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
 	type connOrError struct {
 		conn net.Conn
 		err  error
 	}
 	connChan := make(chan connOrError, 1)
 	go func() {
+		listener.SetDeadline(time.Now().Add(*idleTimeout))
 		conn, err := listener.Accept()
 		connChan <- connOrError{conn, err}
 		close(connChan)
@@ -1047,7 +1048,21 @@
 	listener.Close()
 	listener = nil
 
+	var shimKilledLock sync.Mutex
+	var shimKilled bool
+	waitTimeout := time.AfterFunc(*idleTimeout, func() {
+		shimKilledLock.Lock()
+		shimKilled = true
+		shimKilledLock.Unlock()
+		shim.Process.Kill()
+	})
 	childErr := <-waitChan
+	waitTimeout.Stop()
+	shimKilledLock.Lock()
+	if shimKilled && err == nil {
+		err = errors.New("timeout waiting for the shim to exit.")
+	}
+	shimKilledLock.Unlock()
 	var isValgrindError bool
 	if exitError, ok := childErr.(*exec.ExitError); ok {
 		switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {