only close connection if already open