close the session when write packet returns error