1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:34:48 -07:00

net: fix socket leak in case of Dial failure

Socket descriptors are not closed when fd.connect() fails during generic socket creation.
After a connection failure [ECONNREFUSED] descriptors are left in SYN_SENT state indefinitely (unless they get an explicit RST). Repeated failed connections will eventually cause your program to hit the user/system max-open-files limit.

Fixes #2349.

R=golang-dev, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/5229047
This commit is contained in:
Chris Farmiloe 2011-10-11 12:53:16 -04:00 committed by Russ Cox
parent 1444a08098
commit 4b749567b8

View File

@ -52,6 +52,7 @@ func socket(net string, f, p, t int, la, ra syscall.Sockaddr, toAddr func(syscal
if ra != nil {
if err = fd.connect(ra); err != nil {
closesocket(s)
fd.Close()
return nil, err
}