diff --git a/nano/node/socket.cpp b/nano/node/socket.cpp index 599284b03d..d251c5fe49 100644 --- a/nano/node/socket.cpp +++ b/nano/node/socket.cpp @@ -20,8 +20,8 @@ nano::socket::socket (nano::node & node_a) : tcp_socket{ node_a.io_ctx }, node{ node_a }, next_deadline{ std::numeric_limits::max () }, - last_completion_time{ 0 }, - last_receive_time{ 0 }, + last_completion_time_or_init{ nano::seconds_since_epoch () }, + last_receive_time_or_init{ nano::seconds_since_epoch () }, io_timeout{ node_a.config.tcp_io_timeout }, silent_connection_tolerance_time{ node_a.network_params.network.silent_connection_tolerance_time } { @@ -124,12 +124,12 @@ void nano::socket::start_timer (std::chrono::seconds deadline_a) void nano::socket::stop_timer () { - last_completion_time = nano::seconds_since_epoch (); + last_completion_time_or_init = nano::seconds_since_epoch (); } void nano::socket::update_last_receive_time () { - last_receive_time = nano::seconds_since_epoch (); + last_receive_time_or_init = nano::seconds_since_epoch (); } void nano::socket::checkup () @@ -140,12 +140,12 @@ void nano::socket::checkup () { uint64_t now (nano::seconds_since_epoch ()); auto condition_to_disconnect{ false }; - if (this_l->is_realtime_connection () && now - this_l->last_receive_time > this_l->silent_connection_tolerance_time.count ()) + if (this_l->is_realtime_connection () && (now - this_l->last_receive_time_or_init) > this_l->silent_connection_tolerance_time.count ()) { this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_silent_connection_drop, nano::stat::dir::in); condition_to_disconnect = true; } - if (this_l->next_deadline != std::numeric_limits::max () && now - this_l->last_completion_time > this_l->next_deadline) + if (this_l->next_deadline != std::numeric_limits::max () && (now - this_l->last_completion_time_or_init) > this_l->next_deadline) { this_l->node.stats.inc (nano::stat::type::tcp, nano::stat::detail::tcp_io_timeout_drop, nano::stat::dir::in); condition_to_disconnect = true; diff --git a/nano/node/socket.hpp b/nano/node/socket.hpp index cda8c2bc03..0a6cc975ab 100644 --- a/nano/node/socket.hpp +++ b/nano/node/socket.hpp @@ -115,8 +115,8 @@ class socket : public std::enable_shared_from_this boost::asio::ip::tcp::endpoint remote; std::atomic next_deadline; - std::atomic last_completion_time; - std::atomic last_receive_time; + std::atomic last_completion_time_or_init; + std::atomic last_receive_time_or_init; std::atomic timed_out{ false }; std::atomic io_timeout; std::chrono::seconds silent_connection_tolerance_time;