From cfbc5ebb3b7b4423f203c2b348294b0820e049a1 Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Thu, 8 Feb 2024 19:17:39 -0500 Subject: [PATCH] mobile: Allow ConnectivityManager to handle getifaddrs failures (#32286) ConnectivityManager's enumerateInterfaces relies on getifaddrs. However, getifaddrs could fail for a number of reasons. Instead of RELEASE_ASSERT'ing, which causes crashes, we log the failure and return an empty vector of interfaces, similar to how if there is no support for getifaddrs. Signed-off-by: Ali Beyad --- mobile/library/common/network/connectivity_manager.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/library/common/network/connectivity_manager.cc b/mobile/library/common/network/connectivity_manager.cc index bc75129fb289..6243bb8b3f14 100644 --- a/mobile/library/common/network/connectivity_manager.cc +++ b/mobile/library/common/network/connectivity_manager.cc @@ -409,6 +409,9 @@ InterfacePair ConnectivityManagerImpl::getActiveAlternateInterface(envoy_network return std::make_pair("", nullptr); } +// TODO(abeyad): pass OsSysCallsImpl in as a class dependency instead of directly using +// Api::OsSysCallsSingleton. That'll make it easier to create tests that mock out the +// sys calls behavior. std::vector ConnectivityManagerImpl::enumerateInterfaces([[maybe_unused]] unsigned short family, [[maybe_unused]] unsigned int select_flags, @@ -421,7 +424,10 @@ ConnectivityManagerImpl::enumerateInterfaces([[maybe_unused]] unsigned short fam Api::InterfaceAddressVector interface_addresses{}; const Api::SysCallIntResult rc = Api::OsSysCallsSingleton::get().getifaddrs(interface_addresses); - RELEASE_ASSERT(!rc.return_value_, fmt::format("getiffaddrs error: {}", rc.errno_)); + if (rc.return_value_ != 0) { + ENVOY_LOG_EVERY_POW_2(warn, "getifaddrs error: {}", rc.errno_); + return pairs; + } for (const auto& interface_address : interface_addresses) { const auto family_version = family == AF_INET ? Envoy::Network::Address::IpVersion::v4