From: Brad Fitzpatrick Date: Thu, 22 Dec 2011 01:08:16 +0000 (-0800) Subject: exec: disable the ExtraFiles test on darwin X-Git-Tag: weekly.2011-12-22~35 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=90d56e072f8125be85b77f085e3f576d6533c29d;p=gostls13.git exec: disable the ExtraFiles test on darwin Still a mystery. New issue 2603 filed. R=golang-dev, dsymonds, iant CC=golang-dev https://golang.org/cl/5503063 --- diff --git a/src/pkg/os/exec/exec.go b/src/pkg/os/exec/exec.go index 4c95c1b0da..a00fdad497 100644 --- a/src/pkg/os/exec/exec.go +++ b/src/pkg/os/exec/exec.go @@ -67,6 +67,9 @@ type Cmd struct { // ExtraFiles specifies additional open files to be inherited by the // new process. It does not include standard input, standard output, or // standard error. If non-nil, entry i becomes file descriptor 3+i. + // + // BUG: on OS X 10.6, child processes may sometimes inherit extra fds. + // http://golang.org/issue/2603 ExtraFiles []*os.File // SysProcAttr holds optional, operating system-specific attributes. diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go index 1e0ea97725..c68498047f 100644 --- a/src/pkg/os/exec/exec_test.go +++ b/src/pkg/os/exec/exec_test.go @@ -11,6 +11,8 @@ import ( "io" "io/ioutil" "net" + "net/http" + "net/http/httptest" "os" "runtime" "strconv" @@ -156,6 +158,14 @@ func TestExtraFiles(t *testing.T) { } defer ln.Close() + // Force TLS root certs to be loaded (which might involve + // cgo), to make sure none of that potential C code leaks fds. + ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("Hello")) + })) + defer ts.Close() + http.Get(ts.URL) // ignore result; just calling to force root cert loading + tf, err := ioutil.TempFile("", "") if err != nil { t.Fatalf("TempFile: %v", err) @@ -256,23 +266,31 @@ func TestHelperProcess(*testing.T) { fmt.Printf("ReadAll from fd 3: %v", err) os.Exit(1) } - // Now verify that there are no other open fds. - var files []*os.File - for wantfd := os.Stderr.Fd() + 2; wantfd <= 100; wantfd++ { - f, err := os.Open(os.Args[0]) - if err != nil { - fmt.Printf("error opening file with expected fd %d: %v", wantfd, err) - os.Exit(1) + switch runtime.GOOS { + case "darwin": + // TODO(bradfitz): broken? Sometimes. + // http://golang.org/issue/2603 + // Skip this additional part of the test for now. + default: + // Now verify that there are no other open fds. + var files []*os.File + for wantfd := os.Stderr.Fd() + 2; wantfd <= 100; wantfd++ { + f, err := os.Open(os.Args[0]) + if err != nil { + fmt.Printf("error opening file with expected fd %d: %v", wantfd, err) + os.Exit(1) + } + if got := f.Fd(); got != wantfd { + fmt.Printf("leaked parent file. fd = %d; want %d\n", got, wantfd) + out, _ := Command("lsof", "-p", fmt.Sprint(os.Getpid())).CombinedOutput() + fmt.Print(string(out)) + os.Exit(1) + } + files = append(files, f) } - if got := f.Fd(); got != wantfd { - fmt.Printf("leaked parent file. fd = %d; want %d", got, wantfd) - fmt.Println(Command("lsof", "-p", fmt.Sprint(os.Getpid())).CombinedOutput()) - os.Exit(1) + for _, f := range files { + f.Close() } - files = append(files, f) - } - for _, f := range files { - f.Close() } os.Stderr.Write(bs) case "exit":