Avoid Releasing, Reacquiring lock per iteration in RPC Retry Thread (#38521)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38521
In the RPC Retry Thread, we add retriable futures to a list under the lock, release the lock, add callbacks/set errors to those futures, then re-acquire the lock to clean up the retry map. We can simply clean up the retry map before releasing the lock and not acquire it again - this would be cleaner and may results in better perf if this reduces context switching between threads looking to acquire the retryMapLock.
ghstack-source-id: 104062147
Test Plan: CI, there are thorough tests in the RPC framework to test errors with retries.
Differential Revision: D21563085
fbshipit-source-id: 35e620892da630d082c032f5f9ce16e8a9ffdfaa