I think we can get here also from the raise in line 228 (that is, an error during commit, not rollback). I don't think closing is justified then.