Skip to content

Commit 6f42be7

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 36db10f commit 6f42be7

File tree

1 file changed

+2
-27
lines changed

1 file changed

+2
-27
lines changed

src/net/server_test.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
package net
88

99
import (
10-
"fmt"
1110
"os"
12-
"reflect"
1311
"testing"
1412
)
1513

@@ -190,32 +188,9 @@ func TestUnixAndUnixpacketServer(t *testing.T) {
190188
t.Fatal(err)
191189
}
192190

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-
}
191+
if addr := c.LocalAddr(); addr != nil {
192+
t.Logf("connected %s->%s", addr, lss[i].Listener.Addr())
213193
}
214-
defer func() {
215-
checkNils()
216-
os.Remove(c.LocalAddr().String())
217-
}()
218-
checkNils()
219194

220195
defer c.Close()
221196
trchs = append(trchs, make(chan error, 1))

0 commit comments

Comments
 (0)