From d46621dbab146103e2d2bbba9c1242d8a25b9263 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sun, 16 Dec 2018 17:44:14 +0100 Subject: [PATCH] Consume future outside of client scope (#1466) --- rai/node/bootstrap.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 970f0d03..5524dff0 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -809,7 +809,7 @@ bool rai::bootstrap_attempt::request_frontier (std::unique_lock & lo future = client->promise.get_future (); } lock_a.unlock (); - result = consume_future (future); + result = consume_future (future); // This is out of scope of `client' so when the last reference via boost::asio::io_service is lost and the client is destroyed, the future throws an exception. lock_a.lock (); if (result) { @@ -862,12 +862,15 @@ void rai::bootstrap_attempt::request_push (std::unique_lock & lock_a bool error (false); if (auto connection_shared = connection_frontier_request.lock ()) { - auto client (std::make_shared (connection_shared)); - client->start (); - push = client; - auto future (client->promise.get_future ()); + std::future future; + { + auto client (std::make_shared (connection_shared)); + client->start (); + push = client; + future = client->promise.get_future (); + } lock_a.unlock (); - error = consume_future (future); + error = consume_future (future); // This is out of scope of `client' so when the last reference via boost::asio::io_service is lost and the client is destroyed, the future throws an exception. lock_a.lock (); } if (node->config.logging.network_logging ())