Only close connection if its open