Only close if connection exists