Skip to content

Commit

Permalink
Fix for unit test ipc.asynchronous (nanocurrency#3964)
Browse files Browse the repository at this point in the history
It can fail due to the callback trying to access a destroyed node.
The real problem is likely larger than this little fix and related
to the chaotic way the node shuts down. Leaving the larger fix for
another time, priorities...
  • Loading branch information
dsiganos authored and clemahieu committed Oct 1, 2022
1 parent e01da5d commit 252851f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nano/node/ipc/ipc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,30 @@ class socket_transport : public nano::ipc::transport
// Prepare the next session
auto new_session (std::make_shared<session<SOCKET_TYPE>> (server, context (), config_transport));

acceptor->async_accept (new_session->get_socket (), [this, new_session] (boost::system::error_code const & ec) {
std::weak_ptr<nano::node> nano_weak = server.node.shared ();
acceptor->async_accept (new_session->get_socket (), [this, new_session, nano_weak] (boost::system::error_code const & ec) {
auto node = nano_weak.lock ();
if (!node)
{
return;
}

if (!ec)
{
new_session->read_next_request ();
}
else
{
server.node.logger.always_log ("IPC: acceptor error: ", ec.message ());
node->logger.always_log ("IPC: acceptor error: ", ec.message ());
}

if (ec != boost::asio::error::operation_aborted && acceptor->is_open ())
{
this->accept ();
accept ();
}
else
{
server.node.logger.always_log ("IPC: shutting down");
node->logger.always_log ("IPC: shutting down");
}
});
}
Expand Down

0 comments on commit 252851f

Please sign in to comment.