Make sure that connection gets closed even if an exception is raised