Close executors in BasePcpHandler::Shutdown

The client can call DisconnectFromEndpointManager() explicitly before
BasePcpHandler is shut down. In this case, th executors were not terminated
inside BasePcpHandler::Shutdown()
This caused use-after-free errors in BasePcpHandlerTest.IoError_RequestConnectionFails

PiperOrigin-RevId: 551340708
This commit is contained in:
Janusz Sobczak
2023-07-26 16:00:08 -07:00
committed by Copybara-Service
parent a42cdc7346
commit cae06bd15d
2 changed files with 2 additions and 1 deletions
@@ -84,7 +84,7 @@ BasePcpHandler::~BasePcpHandler() {
}
void BasePcpHandler::Shutdown() {
if (stop_) return;
if (closed_.Set(true)) return;
NEARBY_LOGS(INFO) << "Initiating shutdown of BasePcpHandler("
<< strategy_.GetName() << ")";
DisconnectFromEndpointManager();
@@ -609,6 +609,7 @@ class BasePcpHandler : public PcpHandler,
Strategy strategy_{PcpToStrategy(pcp_)};
EncryptionRunner encryption_runner_;
BwuManager* bwu_manager_;
AtomicBoolean closed_{false};
};
} // namespace connections