Merge pull request #23365 from yashykt/deadlockws

Fix possible deadlock in RemoveExternalConnectivityWatcher
pull/23391/head
Yash Tibrewal 4 years ago committed by GitHub
commit 013f0acf3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/ext/filters/client_channel/client_channel.cc

@ -184,13 +184,19 @@ class ChannelData {
void RemoveExternalConnectivityWatcher(grpc_closure* on_complete, void RemoveExternalConnectivityWatcher(grpc_closure* on_complete,
bool cancel) { bool cancel) {
ExternalConnectivityWatcher* watcher = nullptr;
{
MutexLock lock(&external_watchers_mu_); MutexLock lock(&external_watchers_mu_);
auto it = external_watchers_.find(on_complete); auto it = external_watchers_.find(on_complete);
if (it != external_watchers_.end()) { if (it != external_watchers_.end()) {
if (cancel) it->second->Cancel(); watcher = it->second;
external_watchers_.erase(it); external_watchers_.erase(it);
} }
} }
// watcher->Cancel() will hop into the WorkSerializer, so we have to unlock
// the mutex before calling it.
if (watcher != nullptr && cancel) watcher->Cancel();
}
int NumExternalConnectivityWatchers() const { int NumExternalConnectivityWatchers() const {
MutexLock lock(&external_watchers_mu_); MutexLock lock(&external_watchers_mu_);

Loading…
Cancel
Save