Added connection release handling in error case