Fix race conditions reported by TSAN (#1650)
This commit is contained in:
parent
c5d943ad82
commit
16cb89a0ef
3 changed files with 21 additions and 14 deletions
|
@ -38,23 +38,29 @@ void nano::socket::async_read (std::shared_ptr<std::vector<uint8_t>> buffer_a, s
|
|||
{
|
||||
assert (size_a <= buffer_a->size ());
|
||||
auto this_l (shared_from_this ());
|
||||
start ();
|
||||
boost::asio::async_read (socket_m, boost::asio::buffer (buffer_a->data (), size_a), [this_l, callback_a](boost::system::error_code const & ec, size_t size_a) {
|
||||
this_l->node->stats.add (nano::stat::type::traffic_bootstrap, nano::stat::dir::in, size_a);
|
||||
this_l->stop ();
|
||||
callback_a (ec, size_a);
|
||||
});
|
||||
if (socket_m.is_open ())
|
||||
{
|
||||
start ();
|
||||
boost::asio::async_read (socket_m, boost::asio::buffer (buffer_a->data (), size_a), [this_l, callback_a](boost::system::error_code const & ec, size_t size_a) {
|
||||
this_l->node->stats.add (nano::stat::type::traffic_bootstrap, nano::stat::dir::in, size_a);
|
||||
this_l->stop ();
|
||||
callback_a (ec, size_a);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void nano::socket::async_write (std::shared_ptr<std::vector<uint8_t>> buffer_a, std::function<void(boost::system::error_code const &, size_t)> callback_a)
|
||||
{
|
||||
auto this_l (shared_from_this ());
|
||||
start ();
|
||||
boost::asio::async_write (socket_m, boost::asio::buffer (buffer_a->data (), buffer_a->size ()), [this_l, callback_a, buffer_a](boost::system::error_code const & ec, size_t size_a) {
|
||||
this_l->node->stats.add (nano::stat::type::traffic_bootstrap, nano::stat::dir::out, size_a);
|
||||
this_l->stop ();
|
||||
callback_a (ec, size_a);
|
||||
});
|
||||
if (socket_m.is_open ())
|
||||
{
|
||||
start ();
|
||||
boost::asio::async_write (socket_m, boost::asio::buffer (buffer_a->data (), buffer_a->size ()), [this_l, callback_a, buffer_a](boost::system::error_code const & ec, size_t size_a) {
|
||||
this_l->node->stats.add (nano::stat::type::traffic_bootstrap, nano::stat::dir::out, size_a);
|
||||
this_l->stop ();
|
||||
callback_a (ec, size_a);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void nano::socket::start (std::chrono::steady_clock::time_point timeout_a)
|
||||
|
|
|
@ -130,7 +130,7 @@ void nano::network::receive ()
|
|||
|
||||
void nano::network::process_packets ()
|
||||
{
|
||||
while (on)
|
||||
while (on.load ())
|
||||
{
|
||||
auto data (buffer_container.dequeue ());
|
||||
if (data == nullptr)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <nano/node/wallet.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
|
||||
|
@ -323,7 +324,7 @@ public:
|
|||
boost::asio::ip::udp::resolver resolver;
|
||||
std::vector<boost::thread> packet_processing_threads;
|
||||
nano::node & node;
|
||||
bool on;
|
||||
std::atomic<bool> on;
|
||||
static uint16_t const node_port = nano::nano_network == nano::nano_networks::nano_live_network ? 7075 : 54000;
|
||||
static size_t const buffer_size = 512;
|
||||
static size_t const confirm_req_hashes_max = 6;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue