Join threads if exception happened in constructor

This commit is contained in:
Antonio Andelic 2023-03-06 12:55:02 +00:00
parent b7eef62458
commit 9117c7491d

View File

@ -358,12 +358,27 @@ ZooKeeper::ZooKeeper(
if (!args.auth_scheme.empty())
sendAuth(args.auth_scheme, args.identity);
send_thread = ThreadFromGlobalPool([this] { sendThread(); });
receive_thread = ThreadFromGlobalPool([this] { receiveThread(); });
try
{
send_thread = ThreadFromGlobalPool([this] { sendThread(); });
receive_thread = ThreadFromGlobalPool([this] { receiveThread(); });
initApiVersion();
initApiVersion();
ProfileEvents::increment(ProfileEvents::ZooKeeperInit);
ProfileEvents::increment(ProfileEvents::ZooKeeperInit);
}
catch (...)
{
tryLogCurrentException(log, "Failed to connect to ZooKeeper");
if (send_thread.joinable())
send_thread.join();
if (receive_thread.joinable())
receive_thread.join();
throw;
}
}