Fix bug: close socket when connect failed