]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix socket leak in case of Dial failure
authorChris Farmiloe <chrisfarms@gmail.com>
Tue, 11 Oct 2011 16:53:16 +0000 (12:53 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 11 Oct 2011 16:53:16 +0000 (12:53 -0400)
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

src/pkg/net/sock.go

index 366e050ff3be56099e6df7ef525b52308f52f1c4..2359014ad63ef82cdc1b245007c2ae56b89921c1 100644 (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
                }