]> Cypherpunks repositories - gostls13.git/commitdiff
net: diagnose unexpected nils in TestUnixAndUnixpacketServer
authorBryan C. Mills <bcmills@google.com>
Mon, 22 Nov 2021 15:21:19 +0000 (10:21 -0500)
committerBryan C. Mills <bcmills@google.com>
Mon, 22 Nov 2021 18:55:55 +0000 (18:55 +0000)
For #34611

Change-Id: I31894d58498b2c290ecceccfc004bc817f8969c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/366114
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/server_test.go

index 5192c1e0afc76479ad44d7b2365786f8ec2880c0..33d33b0337aeb4c2422366b4eaa014c418e9ddf1 100644 (file)
@@ -7,7 +7,9 @@
 package net
 
 import (
+       "fmt"
        "os"
+       "reflect"
        "testing"
 )
 
@@ -187,7 +189,34 @@ func TestUnixAndUnixpacketServer(t *testing.T) {
                                }
                                t.Fatal(err)
                        }
-                       defer os.Remove(c.LocalAddr().String())
+
+                       // We really just want to defer os.Remove(c.LocalAddr().String()) here,
+                       // but sometimes that panics due to a nil dereference on the
+                       // solaris-amd64-oraclerel builder (https://golang.org/issue/34611).
+                       // The source of the nil panic is not obvious because there are many
+                       // nillable types involved, so we will temporarily inspect all of them to
+                       // try to get a better idea of what is happening on that platform.
+                       checkNils := func() {
+                               if c == nil {
+                                       panic("Dial returned a nil Conn")
+                               }
+                               if rc := reflect.ValueOf(c); rc.Kind() == reflect.Pointer && rc.IsNil() {
+                                       panic(fmt.Sprintf("Dial returned a nil %T", c))
+                               }
+                               addr := c.LocalAddr()
+                               if addr == nil {
+                                       panic(fmt.Sprintf("(%T).LocalAddr returned a nil Addr", c))
+                               }
+                               if raddr := reflect.ValueOf(addr); raddr.Kind() == reflect.Pointer && raddr.IsNil() {
+                                       panic(fmt.Sprintf("(%T).LocalAddr returned a nil %T", c, addr))
+                               }
+                       }
+                       defer func() {
+                               checkNils()
+                               os.Remove(c.LocalAddr().String())
+                       }()
+                       checkNils()
+
                        defer c.Close()
                        trchs = append(trchs, make(chan error, 1))
                        go transceiver(c, []byte("UNIX AND UNIXPACKET SERVER TEST"), trchs[i])