Make sure connections are closed in the event of an error.