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

[TSAN] start_time data race in bootstrap_client #2698

Merged
merged 1 commit into from
Apr 10, 2020
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
2 changes: 1 addition & 1 deletion nano/node/bootstrap/bootstrap_bulk_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
}
if (connection->block_count++ == 0)
{
connection->start_time = std::chrono::steady_clock::now ();
connection->set_start_time (std::chrono::steady_clock::now ());
}
attempt->total_blocks++;
bool stop_pull (attempt->process_block (block, known_account, pull_blocks, pull.count, block_expected, pull.retry_limit));
Expand Down
11 changes: 9 additions & 2 deletions nano/node/bootstrap/bootstrap_connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ connections (connections_a),
channel (channel_a),
socket (socket_a),
receive_buffer (std::make_shared<std::vector<uint8_t>> ()),
start_time (std::chrono::steady_clock::now ())
start_time_m (std::chrono::steady_clock::now ())
{
++connections->connections_count;
receive_buffer->resize (256);
Expand All @@ -36,9 +36,16 @@ double nano::bootstrap_client::block_rate () const
return static_cast<double> (block_count.load () / elapsed);
}

void nano::bootstrap_client::set_start_time (std::chrono::steady_clock::time_point start_time_a)
{
nano::lock_guard<std::mutex> guard (start_time_mutex);
start_time_m = start_time_a;
}

double nano::bootstrap_client::elapsed_seconds () const
{
return std::chrono::duration_cast<std::chrono::duration<double>> (std::chrono::steady_clock::now () - start_time).count ();
nano::lock_guard<std::mutex> guard (start_time_mutex);
return std::chrono::duration_cast<std::chrono::duration<double>> (std::chrono::steady_clock::now () - start_time_m).count ();
}

void nano::bootstrap_client::stop (bool force)
Expand Down
6 changes: 5 additions & 1 deletion nano/node/bootstrap/bootstrap_connections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ class bootstrap_client final : public std::enable_shared_from_this<bootstrap_cli
void stop (bool force);
double block_rate () const;
double elapsed_seconds () const;
void set_start_time (std::chrono::steady_clock::time_point start_time_a);
std::shared_ptr<nano::node> node;
std::shared_ptr<nano::bootstrap_connections> connections;
std::shared_ptr<nano::transport::channel_tcp> channel;
std::shared_ptr<nano::socket> socket;
std::shared_ptr<std::vector<uint8_t>> receive_buffer;
std::chrono::steady_clock::time_point start_time;
std::atomic<uint64_t> block_count{ 0 };
std::atomic<bool> pending_stop{ false };
std::atomic<bool> hard_stop{ false };

private:
mutable std::mutex start_time_mutex;
std::chrono::steady_clock::time_point start_time_m;
};

class bootstrap_connections final : public std::enable_shared_from_this<bootstrap_connections>
Expand Down