Skip to content

Commit dc5b523

Browse files
committed
net: don't call forceCloseSockets in non-TestMain functions
forceCloseSockets is just designed as a kingston valve for TestMain function and is not suitable to keep track of inflight sockets. Fixes #15525. Change-Id: Id967fe5b8da99bb08b699cc45e07bbc3dfc3ae3d Reviewed-on: https://go-review.googlesource.com/23505 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Mikio Hara <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 4e01c13 commit dc5b523

File tree

5 files changed

+5
-18
lines changed

5 files changed

+5
-18
lines changed

src/net/dial_test.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,14 @@ func TestDialTimeoutFDLeak(t *testing.T) {
8787
// socktest.Switch.
8888
// It may happen when the Dial call bumps against TCP
8989
// simultaneous open. See selfConnect in tcpsock_posix.go.
90-
defer func() {
91-
sw.Set(socktest.FilterClose, nil)
92-
forceCloseSockets()
93-
}()
90+
defer func() { sw.Set(socktest.FilterClose, nil) }()
9491
var mu sync.Mutex
9592
var attempts int
9693
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
9794
mu.Lock()
9895
attempts++
9996
mu.Unlock()
100-
return nil, errTimedout
97+
return nil, nil
10198
})
10299

103100
const N = 100

src/net/main_plan9_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func installTestHooks() {}
88

99
func uninstallTestHooks() {}
1010

11+
// forceCloseSockets must be called only from TestMain.
1112
func forceCloseSockets() {}
1213

1314
func enableSocketConnect() {}

src/net/main_unix_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func uninstallTestHooks() {
4545
}
4646
}
4747

48+
// forceCloseSockets must be called only from TestMain.
4849
func forceCloseSockets() {
4950
for s := range sw.Sockets() {
5051
closeFunc(s)

src/net/main_windows_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func uninstallTestHooks() {
3232
acceptFunc = origAccept
3333
}
3434

35+
// forceCloseSockets must be called only from TestMain.
3536
func forceCloseSockets() {
3637
for s := range sw.Sockets() {
3738
closeFunc(s)

src/net/timeout_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ func TestDialTimeout(t *testing.T) {
4141
defer func() { testHookDialChannel = origTestHookDialChannel }()
4242
defer sw.Set(socktest.FilterConnect, nil)
4343

44-
// Avoid tracking open-close jitterbugs between netFD and
45-
// socket that leads to confusion of information inside
46-
// socktest.Switch.
47-
// It may happen when the Dial call bumps against TCP
48-
// simultaneous open. See selfConnect in tcpsock_posix.go.
49-
defer func() {
50-
sw.Set(socktest.FilterClose, nil)
51-
forceCloseSockets()
52-
}()
53-
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
54-
return nil, errTimedout
55-
})
56-
5744
for i, tt := range dialTimeoutTests {
5845
switch runtime.GOOS {
5946
case "plan9", "windows":

0 commit comments

Comments
 (0)