]> Cypherpunks repositories - gostls13.git/commitdiff
exec: disable the ExtraFiles test on darwin
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 22 Dec 2011 01:08:16 +0000 (17:08 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 22 Dec 2011 01:08:16 +0000 (17:08 -0800)
Still a mystery. New issue 2603 filed.

R=golang-dev, dsymonds, iant
CC=golang-dev
https://golang.org/cl/5503063

src/pkg/os/exec/exec.go
src/pkg/os/exec/exec_test.go

index 4c95c1b0dac5a750592365eb4311895e378f9e98..a00fdad497faa94a336242014ad6d29a9f51e22b 100644 (file)
@@ -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.
index 1e0ea9772510bcd02a903f9d7e2d70b17ec8c86f..c68498047faa6ff159c85edaf06ac74b28ad6154 100644 (file)
@@ -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":