try closing socket if connection fails.

i think we should try closing the socket if the connection fails