Patchwork libgo patch committed: Fix test

login
register
mail settings
Submitter Ian Taylor
Date Oct. 26, 2012, 5:50 p.m.
Message ID <mcrip9xnmw6.fsf@google.com>
Download mbox | patch
Permalink /patch/194549/
State New
Headers show

Comments

Ian Taylor - Oct. 26, 2012, 5:50 p.m.
Uros investigated a libgo testsuite failure on Alpha GNU/Linux that
looked like a GC bug but turned out to simply be a testsuite bug.  In Go
when the garbage collector collects an os.File it closes the file
descriptor.  The syscall/creds_test test would call socketpair(), and
defer closing both descriptors.  Then it would turn the file descriptors
into os.File pointers using os.NewFile, but it would not close those
os.File pointers.  So when the test returned, the file descriptors would
be closed, but the os.File pointers would remain in the heap,
inaccessible.  When the garbage collector noticed that, it would run the
finalizers, and close the descriptors again.  That is normally harmless,
as the finalizer ignored the errors.  However, in this case a later test
would call socketpair again and happened to get the same file descriptor
numbers back.  Then the garbage collector ran, and closed them before
the test was complete.  So the test failed.

This patch fixes the problem.  Test ran on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 158890b70d33 libgo/go/syscall/creds_test.go
--- a/libgo/go/syscall/creds_test.go	Thu Oct 25 11:25:35 2012 -0700
+++ b/libgo/go/syscall/creds_test.go	Fri Oct 26 10:38:15 2012 -0700
@@ -31,14 +31,18 @@ 
 		t.Fatalf("SetsockoptInt: %v", err)
 	}
 
-	srv, err := net.FileConn(os.NewFile(uintptr(fds[0]), ""))
+	srvFile := os.NewFile(uintptr(fds[0]), "server")
+	defer srvFile.Close()
+	srv, err := net.FileConn(srvFile)
 	if err != nil {
 		t.Errorf("FileConn: %v", err)
 		return
 	}
 	defer srv.Close()
 
-	cli, err := net.FileConn(os.NewFile(uintptr(fds[1]), ""))
+	cliFile := os.NewFile(uintptr(fds[1]), "client")
+	defer cliFile.Close()
+	cli, err := net.FileConn(cliFile)
 	if err != nil {
 		t.Errorf("FileConn: %v", err)
 		return