Skip to content

Commit

Permalink
client_channel: fix crash when cancelling a watch after SHUTDOWN (#30885
Browse files Browse the repository at this point in the history
) (#30928)
  • Loading branch information
markdroth committed Sep 9, 2022
1 parent babe805 commit dee197f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/ext/filters/client_channel/client_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,14 @@ void ClientChannel::ExternalConnectivityWatcher::Notify(
// Hop back into the work_serializer to clean up.
// Not needed in state SHUTDOWN, because the tracker will
// automatically remove all watchers in that case.
// Note: The callback takes a ref in case the ref inside the state tracker
// gets removed before the callback runs via a SHUTDOWN notification.
if (state != GRPC_CHANNEL_SHUTDOWN) {
Ref(DEBUG_LOCATION, "RemoveWatcherLocked()").release();
chand_->work_serializer_->Run(
[this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(*chand_->work_serializer_) {
RemoveWatcherLocked();
Unref(DEBUG_LOCATION, "RemoveWatcherLocked()");
},
DEBUG_LOCATION);
}
Expand All @@ -754,9 +758,13 @@ void ClientChannel::ExternalConnectivityWatcher::Cancel() {
}
ExecCtx::Run(DEBUG_LOCATION, on_complete_, GRPC_ERROR_CANCELLED);
// Hop back into the work_serializer to clean up.
// Note: The callback takes a ref in case the ref inside the state tracker
// gets removed before the callback runs via a SHUTDOWN notification.
Ref(DEBUG_LOCATION, "RemoveWatcherLocked()").release();
chand_->work_serializer_->Run(
[this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(*chand_->work_serializer_) {
RemoveWatcherLocked();
Unref(DEBUG_LOCATION, "RemoveWatcherLocked()");
},
DEBUG_LOCATION);
}
Expand Down

0 comments on commit dee197f

Please sign in to comment.