mirror of
https://github.com/golang/go
synced 2024-11-16 19:14:43 -07:00
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>
This commit is contained in:
parent
9e94cc3666
commit
2d7ae3fbd8
@ -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])
|
||||
|
Loading…
Reference in New Issue
Block a user