Skip to content

Commit 2d7ae3f

Browse files
author
Bryan C. Mills
committed
net: diagnose unexpected nils in TestUnixAndUnixpacketServer
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>
1 parent 9e94cc3 commit 2d7ae3f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/net/server_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
package net
88

99
import (
10+
"fmt"
1011
"os"
12+
"reflect"
1113
"testing"
1214
)
1315

@@ -187,7 +189,34 @@ func TestUnixAndUnixpacketServer(t *testing.T) {
187189
}
188190
t.Fatal(err)
189191
}
190-
defer os.Remove(c.LocalAddr().String())
192+
193+
// We really just want to defer os.Remove(c.LocalAddr().String()) here,
194+
// but sometimes that panics due to a nil dereference on the
195+
// solaris-amd64-oraclerel builder (https://golang.org/issue/34611).
196+
// The source of the nil panic is not obvious because there are many
197+
// nillable types involved, so we will temporarily inspect all of them to
198+
// try to get a better idea of what is happening on that platform.
199+
checkNils := func() {
200+
if c == nil {
201+
panic("Dial returned a nil Conn")
202+
}
203+
if rc := reflect.ValueOf(c); rc.Kind() == reflect.Pointer && rc.IsNil() {
204+
panic(fmt.Sprintf("Dial returned a nil %T", c))
205+
}
206+
addr := c.LocalAddr()
207+
if addr == nil {
208+
panic(fmt.Sprintf("(%T).LocalAddr returned a nil Addr", c))
209+
}
210+
if raddr := reflect.ValueOf(addr); raddr.Kind() == reflect.Pointer && raddr.IsNil() {
211+
panic(fmt.Sprintf("(%T).LocalAddr returned a nil %T", c, addr))
212+
}
213+
}
214+
defer func() {
215+
checkNils()
216+
os.Remove(c.LocalAddr().String())
217+
}()
218+
checkNils()
219+
191220
defer c.Close()
192221
trchs = append(trchs, make(chan error, 1))
193222
go transceiver(c, []byte("UNIX AND UNIXPACKET SERVER TEST"), trchs[i])

0 commit comments

Comments
 (0)