make sure connection gets closed on exceptions