Fix for unit test ipc.asynchronous (#3964)

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...
This commit is contained in:
Dimitrios Siganos 2022-09-29 13:01:46 +01:00 committed by GitHub
commit 5fcb8e09a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -511,23 +511,30 @@ public:
// 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");
}
});
}