(Backport) =rem #3633 Fix race between EndpointWriter Terminated and TakeOver