From 420ee4927bdd74ed1bbf385041a4a1be8cb3906e Mon Sep 17 00:00:00 2001 From: hai007 Date: Fri, 12 Feb 2021 12:25:59 -0800 Subject: [PATCH] cl/357006793 Close all channels on duplicate BwuPathAvailable frame. --- cpp/core/internal/bwu_manager.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/cpp/core/internal/bwu_manager.cc b/cpp/core/internal/bwu_manager.cc index 9c2f33fc..6cfeab48 100644 --- a/cpp/core/internal/bwu_manager.cc +++ b/cpp/core/internal/bwu_manager.cc @@ -401,12 +401,29 @@ void BwuManager::ProcessBwuPathAvailableEvent( if (FeatureFlags::GetInstance() .GetFlags() .disallow_out_of_order_bwu_avail_event) { - NEARBY_LOG(WARNING, - "BandwidthUpgradeManager is ignoring bandwidth upgrade for " - "endpoint %s because we're already upgrading bandwidth for " - "that endpoint. Something may have gone wrong, as it seems " - "we're out of sync with the remote device.", + NEARBY_LOG(ERROR, + "BandwidthUpgradeManager received a duplicate bandwidth " + "upgrade for endpoint %s. We're out of sync with the remote " + "device and cannot recover; closing all channels.", endpoint_id.c_str()); + + auto item = previous_endpoint_channels_.extract(endpoint_id); + if (!item.empty()) { + std::shared_ptr previous_endpoint_channel = + item.mapped(); + if (previous_endpoint_channel) { + previous_endpoint_channel->Close(DisconnectionReason::IO_ERROR); + } + } + std::shared_ptr new_channel = + channel_manager_->GetChannelForEndpoint(endpoint_id); + if (new_channel) { + // The upgraded channel never finished upgrading, and therefore is still + // paused. + new_channel->Resume(); + new_channel->Close(DisconnectionReason::IO_ERROR); + } + return; } }