net/interfaces: fix test hang on Darwin

This test could hang because the subprocess was blocked on writing to
the stdout pipe if we find the address we're looking for early in the
output.

Updates #cleanup

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I68d82c22a5d782098187ae6d8577e43063b72573
This commit is contained in:
Andrew Dunham 2024-03-06 20:11:46 -05:00
parent 62cf83eb92
commit 9884d06b80
1 changed files with 2 additions and 0 deletions

View File

@ -5,6 +5,7 @@ package interfaces
import (
"errors"
"io"
"net/netip"
"os/exec"
"testing"
@ -69,6 +70,7 @@ func likelyHomeRouterIPDarwinExec() (ret netip.Addr, netif string, ok bool) {
return
}
defer cmd.Wait()
defer io.Copy(io.Discard, stdout) // clear the pipe to prevent hangs
var f []mem.RO
lineread.Reader(stdout, func(lineb []byte) error {