Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
net: Socket connection stuck in SYN_SENT when connection fails #2349
I have been using http.Client with proxy connections and have noticed that a ton of connections get stuck in SYN_SENT after a while. Eventually resulting in "too many open files" errors which obviously causes serious problems. To see this issue I have included a little example program [syn_stuck.go] that will open a large number of HTTP connections via non-existant proxy, and then tell you to go check "lsof". I've tried it on both OSX and Linux with same results. After a bit of digging I believe the issue is with net/sock.go:56 .... when an fd.connect() fails the socket is not closed. (patch attached). Running syn_stuck + lsof after the patch gives the expected result.