I think you should set the flag here, only if the logout message was sent to the endpoint successfully.