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

Revert the thread_pool destruction on shutdown, revert back the fix for issue https://github.com/chriskohlhoff/asio/issues/431 #751

Merged
merged 3 commits into from
Jan 8, 2021
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 @@ -24,6 +24,7 @@
#include <boost/asio/thread_pool.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/smart_ptr/atomic_shared_ptr.hpp>
#include <boost/asio/steady_timer.hpp>

#include "hazelcast/util/Sync.h"
#include "hazelcast/client/exception/protocol_exceptions.h"
Expand Down Expand Up @@ -179,6 +180,8 @@ namespace hazelcast {
*/
std::chrono::steady_clock::time_point pending_response_received_time_;

std::shared_ptr<boost::asio::steady_timer> retry_timer_;

ClientInvocation(spi::ClientContext &client_context,
std::shared_ptr<protocol::ClientMessage> &&message,
const std::string &name, int partition = UNASSIGNED_PARTITION,
Expand Down
14 changes: 10 additions & 4 deletions hazelcast/src/hazelcast/client/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ namespace hazelcast {
submit_connect_to_cluster_task();
}

} catch (exception::iexception &e) {
} catch (std::exception &e) {
HZ_LOG(logger_, warning,
boost::str(boost::format("Could not connect to any cluster, "
"shutting down the client: %1%")
% e)
boost::str(boost::format("Could not connect to any cluster, "
"shutting down the client: %1%")
% e.what())
);

shutdown_with_external_thread(client_.get_hazelcast_client_implementation());
Expand Down Expand Up @@ -645,6 +645,12 @@ namespace hazelcast {
on_connection_close(connection);
return nullptr;
}

// If the client is shutdown in parallel, we need to close this new connection.
if (!client_.get_lifecycle_service().is_running()) {
connection->close("Client is shutdown");
}

return connection;
}

Expand Down
2 changes: 1 addition & 1 deletion hazelcast/src/hazelcast/client/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ namespace hazelcast {
// progressive retry delay
int64_t delayMillis = util::min<int64_t>(static_cast<int64_t>(1) << (invoke_count_ - MAX_FAST_INVOCATION_COUNT),
std::chrono::duration_cast<std::chrono::milliseconds>(retry_pause_).count());
execution_service_->schedule(command, std::chrono::milliseconds(delayMillis));
retry_timer_ = execution_service_->schedule(command, std::chrono::milliseconds(delayMillis));
}
}

Expand Down
10 changes: 0 additions & 10 deletions hazelcast/src/hazelcast/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,16 +1023,6 @@ namespace hazelcast {

void hz_thread_pool::shutdown_gracefully() {
pool_->join();
pool_->stop();

#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
// needed due to bug https://github.com/chriskohlhoff/asio/issues/431
boost::asio::use_service<boost::asio::detail::win_iocp_io_context>(*pool_).stop();
// We need the following line so that the windows threads can be terminated. Otherwise,
// the threads stay dangling and cause resource leakage. Normally, the pool_ is destructed on client
// destruction but somehow it needs to be triggered at this point.
pool_.reset();
#endif
}

boost::asio::thread_pool::executor_type hz_thread_pool::get_executor() const {
Expand Down