mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
[Nearby Connections] Add methods to shutdown executors in bwu_manager
Adding methods that allow us to shutdown executors in bwu_manager during Nearby Connections shutdown process to prevent potential crashes. PiperOrigin-RevId: 466425604
This commit is contained in:
@@ -129,8 +129,7 @@ void BwuManager::Shutdown() {
|
||||
V1Frame::BANDWIDTH_UPGRADE_NEGOTIATION, this);
|
||||
|
||||
// Stop all the ongoing Runnables (as gracefully as possible).
|
||||
alarm_executor_.Shutdown();
|
||||
serial_executor_.Shutdown();
|
||||
ShutdownExecutors();
|
||||
|
||||
// After worker threads are down we became exclusive owners of data and
|
||||
// may access it from current thread.
|
||||
@@ -162,6 +161,11 @@ void BwuManager::InvokeOnIncomingConnectionForTesting(
|
||||
OnIncomingConnection(client, std::move(mutable_connection));
|
||||
}
|
||||
|
||||
void BwuManager::ShutdownExecutors() {
|
||||
alarm_executor_.Shutdown();
|
||||
serial_executor_.Shutdown();
|
||||
}
|
||||
|
||||
void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
|
||||
const std::string& endpoint_id,
|
||||
Medium new_medium) {
|
||||
|
||||
@@ -108,6 +108,11 @@ class BwuManager : public EndpointManager::FrameProcessor {
|
||||
ClientProxy* client,
|
||||
std::unique_ptr<BwuHandler::IncomingSocketConnection> mutable_connection);
|
||||
|
||||
// Shutdown the executors during Nearby Connections shutdown process before
|
||||
// Core objects destruction so that no task will be run/posted after
|
||||
// ClientProxy objects are deleted.
|
||||
void ShutdownExecutors();
|
||||
|
||||
private:
|
||||
static constexpr absl::Duration kReadClientIntroductionFrameTimeout =
|
||||
absl::Seconds(5);
|
||||
|
||||
@@ -83,6 +83,8 @@ class MockServiceController : public ServiceController {
|
||||
MOCK_METHOD(void, DisconnectFromEndpoint,
|
||||
(ClientProxy * client, const std::string& endpoint_id),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, ShutdownBwuManagerExecutors, (), (override));
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -142,6 +142,10 @@ void OfflineServiceController::DisconnectFromEndpoint(
|
||||
endpoint_manager_.UnregisterEndpoint(client, endpoint_id);
|
||||
}
|
||||
|
||||
void OfflineServiceController::ShutdownBwuManagerExecutors() {
|
||||
bwu_manager_.ShutdownExecutors();
|
||||
}
|
||||
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
@@ -77,6 +77,8 @@ class OfflineServiceController : public ServiceController {
|
||||
|
||||
void Stop() override;
|
||||
|
||||
void ShutdownBwuManagerExecutors() override;
|
||||
|
||||
private:
|
||||
// Note that the order of declaration of these is crucial, because we depend
|
||||
// on the destructors running (strictly) in the reverse order; a deviation
|
||||
|
||||
@@ -56,6 +56,10 @@ class ServiceController {
|
||||
// controller are affected.
|
||||
virtual void Stop() = 0;
|
||||
|
||||
// Shuts down executors in the BwuManager. After that no tasks should be
|
||||
// running on or posted to BwuManager.
|
||||
virtual void ShutdownBwuManagerExecutors() = 0;
|
||||
|
||||
// Starts advertising an endpoint for a local app.
|
||||
virtual Status StartAdvertising(ClientProxy* client,
|
||||
const std::string& service_id,
|
||||
|
||||
@@ -368,6 +368,7 @@ void ServiceControllerRouter::FinishClientSession(ClientProxy* client) {
|
||||
// Stop any advertising and discovery that may be underway due to this client.
|
||||
GetServiceController()->StopAdvertising(client);
|
||||
GetServiceController()->StopDiscovery(client);
|
||||
GetServiceController()->ShutdownBwuManagerExecutors();
|
||||
|
||||
// Finally, clear all state maintained by this client.
|
||||
client->Reset();
|
||||
|
||||
Reference in New Issue
Block a user