Skip to content

Commit

Permalink
Merge pull request #4719 from clemahieu/tsan_fixes
Browse files Browse the repository at this point in the history
Fix correctness, sanity check, and resolve shutdown issue.
  • Loading branch information
clemahieu committed Sep 5, 2024
1 parent ba8870e commit bb1604e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions nano/node/active_elections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ bool nano::active_elections::erase (nano::qualified_root const & root_a)
auto root_it (roots.get<tag_root> ().find (root_a));
if (root_it != roots.get<tag_root> ().end ())
{
release_assert (root_it->election->qualified_root == root_a);
cleanup_election (lock, root_it->election);
return true;
}
Expand Down
8 changes: 6 additions & 2 deletions nano/node/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ void nano::confirming_set::run_batch (std::unique_lock<std::mutex> & lock)
notification.cemented.swap (cemented);
notification.already_cemented.swap (already);

// Wait for the worker thread if too many notifications are queued
std::unique_lock lock{ mutex };
while (notification_workers.num_queued_tasks () >= config.max_queued_notifications)
{
stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown);
std::this_thread::sleep_for (100ms);
condition.wait_for (lock, 100ms, [this] { return stopped; });
if (stopped)
{
return;
}
}

notification_workers.push_task ([this, notification = std::move (notification)] () {
Expand Down
3 changes: 2 additions & 1 deletion nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ std::vector<nano::representative> nano::rep_crawler::representatives (std::size_
}

std::vector<nano::representative> result;
for (auto const & [weight, rep] : ordered | std::views::take (count))
for (auto i = ordered.begin (), n = ordered.end (); i != n && result.size () < count; ++i)
{
auto const & [weight, rep] = *i;
result.push_back ({ rep.account, rep.channel });
}
return result;
Expand Down
12 changes: 8 additions & 4 deletions nano/node/unchecked_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ void nano::unchecked_map::query_impl (nano::block_hash const & hash)

std::unique_ptr<nano::container_info_component> nano::unchecked_map::collect_container_info (const std::string & name)
{
nano::lock_guard<nano::mutex> lock{ mutex };

auto composite = std::make_unique<container_info_composite> (name);
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "entries", entries.size (), sizeof (decltype (entries)::value_type) }));
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "queries", buffer.size (), sizeof (decltype (buffer)::value_type) }));
{
std::lock_guard guard{ entries_mutex };
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "entries", entries.size (), sizeof (decltype (entries)::value_type) }));
}
{
nano::lock_guard<nano::mutex> lock{ mutex };
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "queries", buffer.size (), sizeof (decltype (buffer)::value_type) }));
}
return composite;
}
2 changes: 2 additions & 0 deletions tsan_suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ race:mdb.c
race:rocksdb
race:Rijndael::Base::FillEncTable
race:Rijndael::Base::FillDecTable
race:CryptoPP::Rijndael
race:boost::asio::detail::conditionally_enabled_mutex::scoped_lock::scoped_lock

0 comments on commit bb1604e

Please sign in to comment.