Fix bug: close socket when connect failed

We should close the Socket when connect failed, i didnot find it close the socket in the Function: attempt_connect.
Is there other code to close the bad socket?