making sure pipe exists when trying to close it