Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client may crash during shutdown when ShutdownTask is being run #430

Merged
merged 3 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ namespace hazelcast {

private:
spi::ClientContext &client;
std::string name;
};

class TimeoutAuthenticationTask : public util::Runnable {
Expand Down Expand Up @@ -318,8 +319,6 @@ namespace hazelcast {
util::Atomic<boost::shared_ptr<protocol::Principal> > principal;
std::auto_ptr<ClientConnectionStrategy> connectionStrategy;
boost::shared_ptr<util::impl::SimpleExecutorService> clusterConnectionExecutor;
// This queue is used for avoiding memory leak
util::SynchronizedQueue<util::Thread> shutdownThreads;
int32_t connectionAttemptPeriod;
int32_t connectionAttemptLimit;
bool shuffleMemberList;
Expand Down
62 changes: 0 additions & 62 deletions hazelcast/include/hazelcast/client/connection/HeartBeater.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -774,10 +774,16 @@ namespace hazelcast {
} catch (exception::IException &e) {
connectionManager.logger.warning() << "Could not connect to cluster, shutting down the client. "
<< e.getMessage();
boost::shared_ptr<util::Thread> shutdownThread(new util::Thread(
boost::shared_ptr<util::Runnable>(new ShutdownTask(connectionManager.client))));
/**
* Allocate this thread on heap. Since we do not want this thread to be deleted while thread is
* executing we can not keep it a shared pointer in the HazelcastClient (There is a possibility that
* it may be deleted during client shutdown and the object being destructed.).
*
* TODO: Find a way not to leak this object and also manage the lifecycle of the destructed objects.
*/
util::Thread *shutdownThread = new util::Thread(
boost::shared_ptr<util::Runnable>(new ShutdownTask(connectionManager.client)));
shutdownThread->start();
connectionManager.shutdownThreads.offer(shutdownThread);

throw;
}
Expand All @@ -788,18 +794,19 @@ namespace hazelcast {
}

ClientConnectionManagerImpl::ShutdownTask::ShutdownTask(spi::ClientContext &client)
: client(client) {}
: client(client), name(client.getName() + ".clientShutdown-") {}

void ClientConnectionManagerImpl::ShutdownTask::run() {
try {
client.getLifecycleService().shutdown();
} catch (exception::IException &exception) {
util::ILogger::getLogger().severe() << "Exception during client shutdown: " << exception;
util::ILogger::getLogger().severe() << "Exception during client shutdown task " <<
name << ":" << exception;
}
}

const std::string ClientConnectionManagerImpl::ShutdownTask::getName() const {
return client.getName() + ".clientShutdown-";
return name;
}

void ClientConnectionManagerImpl::TimeoutAuthenticationTask::run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace hazelcast {
const boost::shared_ptr<exception::IException> &t) {
if (partitionService.client.getLifecycleService().isRunning()) {
partitionService.logger.warning() << "Error while fetching cluster partition table! Cause:"
<< t;
<< *t;
}
}

Expand Down