close socket when the connection is resolved