diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-12-09 11:54:46 -0500 |
---|---|---|
committer | Bryan Mills <bcmills@google.com> | 2021-12-13 15:47:32 +0000 |
commit | 6f42be78bbc107beef8b6eb61a794355e07120ca (patch) | |
tree | 22376ddd310a8479cbe91f5b04c7a5ae33ab7b3c | |
parent | 36db10f3cb916a1b97af3bfd4be7e3a2932185f8 (diff) | |
download | go-6f42be78bbc107beef8b6eb61a794355e07120ca.tar.gz go-6f42be78bbc107beef8b6eb61a794355e07120ca.zip |
net: do not try to remove the LocalAddr of a unix socket
TestUnixAndUnixpacketServer deferred a call to os.Remove on the local
address of a dialed unix domain socket, in an attempt to remove the
socket from the server. However, that call appears to be neither
necessary nor correct.
In this test, the file that needs to be unlinked is the one attached
to the listener — but the listener's Close method already does that
(see the Unlink call in (*UnixListener).close), so there is no need
for the test itself to do the same.
Moreover, the local address is not something that is sensible to
delete — on Linux, it is empirically always the literal string "@" —
and the Addr returned by c.LocalAddr is not reliably non-nil on all
platforms (see #34611).
Since we don't need to do anything with the local address, we shouldn't.
At best, this is a benign Remove of a file that doesn't exist anyway;
at worst, it is a nil-panic.
Fixes #34611
Change-Id: Ie072b3388d884d60e819d1df210fa7d3e2eed124
Reviewed-on: https://go-review.googlesource.com/c/go/+/370695
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | src/net/server_test.go | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/src/net/server_test.go b/src/net/server_test.go index 33d33b0337..ae1c1619ed 100644 --- a/src/net/server_test.go +++ b/src/net/server_test.go @@ -7,9 +7,7 @@ package net import ( - "fmt" "os" - "reflect" "testing" ) @@ -190,32 +188,9 @@ func TestUnixAndUnixpacketServer(t *testing.T) { t.Fatal(err) } - // 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)) - } + if addr := c.LocalAddr(); addr != nil { + t.Logf("connected %s->%s", addr, lss[i].Listener.Addr()) } - defer func() { - checkNils() - os.Remove(c.LocalAddr().String()) - }() - checkNils() defer c.Close() trchs = append(trchs, make(chan error, 1)) |