mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <iant@golang.org> Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
4e01c132d0
commit
dc5b5239e8
5 changed files with 5 additions and 18 deletions
|
|
@ -87,17 +87,14 @@ func TestDialTimeoutFDLeak(t *testing.T) {
|
||||||
// socktest.Switch.
|
// socktest.Switch.
|
||||||
// It may happen when the Dial call bumps against TCP
|
// It may happen when the Dial call bumps against TCP
|
||||||
// simultaneous open. See selfConnect in tcpsock_posix.go.
|
// simultaneous open. See selfConnect in tcpsock_posix.go.
|
||||||
defer func() {
|
defer func() { sw.Set(socktest.FilterClose, nil) }()
|
||||||
sw.Set(socktest.FilterClose, nil)
|
|
||||||
forceCloseSockets()
|
|
||||||
}()
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var attempts int
|
var attempts int
|
||||||
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
|
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
attempts++
|
attempts++
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
return nil, errTimedout
|
return nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
const N = 100
|
const N = 100
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ func installTestHooks() {}
|
||||||
|
|
||||||
func uninstallTestHooks() {}
|
func uninstallTestHooks() {}
|
||||||
|
|
||||||
|
// forceCloseSockets must be called only from TestMain.
|
||||||
func forceCloseSockets() {}
|
func forceCloseSockets() {}
|
||||||
|
|
||||||
func enableSocketConnect() {}
|
func enableSocketConnect() {}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ func uninstallTestHooks() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forceCloseSockets must be called only from TestMain.
|
||||||
func forceCloseSockets() {
|
func forceCloseSockets() {
|
||||||
for s := range sw.Sockets() {
|
for s := range sw.Sockets() {
|
||||||
closeFunc(s)
|
closeFunc(s)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ func uninstallTestHooks() {
|
||||||
acceptFunc = origAccept
|
acceptFunc = origAccept
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// forceCloseSockets must be called only from TestMain.
|
||||||
func forceCloseSockets() {
|
func forceCloseSockets() {
|
||||||
for s := range sw.Sockets() {
|
for s := range sw.Sockets() {
|
||||||
closeFunc(s)
|
closeFunc(s)
|
||||||
|
|
|
||||||
|
|
@ -41,19 +41,6 @@ func TestDialTimeout(t *testing.T) {
|
||||||
defer func() { testHookDialChannel = origTestHookDialChannel }()
|
defer func() { testHookDialChannel = origTestHookDialChannel }()
|
||||||
defer sw.Set(socktest.FilterConnect, nil)
|
defer sw.Set(socktest.FilterConnect, nil)
|
||||||
|
|
||||||
// Avoid tracking open-close jitterbugs between netFD and
|
|
||||||
// socket that leads to confusion of information inside
|
|
||||||
// socktest.Switch.
|
|
||||||
// It may happen when the Dial call bumps against TCP
|
|
||||||
// simultaneous open. See selfConnect in tcpsock_posix.go.
|
|
||||||
defer func() {
|
|
||||||
sw.Set(socktest.FilterClose, nil)
|
|
||||||
forceCloseSockets()
|
|
||||||
}()
|
|
||||||
sw.Set(socktest.FilterClose, func(so *socktest.Status) (socktest.AfterFilter, error) {
|
|
||||||
return nil, errTimedout
|
|
||||||
})
|
|
||||||
|
|
||||||
for i, tt := range dialTimeoutTests {
|
for i, tt := range dialTimeoutTests {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "plan9", "windows":
|
case "plan9", "windows":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue