Close connection properly in error case. Pass error to done callback.