Fix handling of EOFException

Also, made rollback a bit more robust, so that it will reconnect if
there is an error. And extracted a couple helper methods to cleanup code
Yes, it's technically redundant, because retry sets the pending to 0, but conceptually, the status should be rolled back when the connection is rolled back.