RPC stop action can take a long time to close the node down (#2135)

* RPC stop action can take a long time to close node down

* Formatting
This commit is contained in:
Wesley Shillingford 2019-07-09 07:52:17 +01:00 committed by GitHub
commit 0b3f0f518a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View file

@ -133,8 +133,11 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
{
throw std::runtime_error ("Could not deserialize rpc_config file");
}
rpc_handler = std::make_unique<nano::inprocess_rpc_handler> (*node, config.rpc, [&ipc_server]() {
rpc_handler = std::make_unique<nano::inprocess_rpc_handler> (*node, config.rpc, [&ipc_server, &alarm, &io_ctx]() {
ipc_server.stop ();
alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (3), [&io_ctx]() {
io_ctx.stop ();
});
});
rpc = nano::get_rpc (io_ctx, rpc_config, *rpc_handler);
rpc->start ();

View file

@ -158,6 +158,13 @@ void nano::confirmation_height_processor::add_confirmation_height (nano::block_h
collect_unconfirmed_receive_and_sources_for_account (block_height, iterated_height, current, account, read_transaction);
}
// Exit early when the processor has been stopped, otherwise this function may take a
// while (and hence keep the process running) if updating a long chain.
if (stopped)
{
break;
}
// No longer need the read transaction
read_transaction.reset ();
@ -246,13 +253,6 @@ void nano::confirmation_height_processor::add_confirmation_height (nano::block_h
}
}
// Exit early when the processor has been stopped, otherwise this function may take a
// while (and hence keep the process running) if updating a long chain.
if (stopped)
{
break;
}
read_transaction.renew ();
} while (!receive_source_pairs.empty () || current != hash_a);
}
@ -328,7 +328,7 @@ void nano::confirmation_height_processor::collect_unconfirmed_receive_and_source
// Store heights of blocks
constexpr auto height_not_set = std::numeric_limits<uint64_t>::max ();
auto next_height = height_not_set;
while ((num_to_confirm > 0) && !hash.is_zero ())
while ((num_to_confirm > 0) && !hash.is_zero () && !stopped)
{
nano::block_sideband sideband;
auto block (store.block_get (transaction_a, hash, &sideband));

View file

@ -129,6 +129,9 @@ public:
// Note that if the rpc action is async, the shared_ptr<json_handler> lifetime will be extended by the action handler
auto handler (std::make_shared<nano::json_handler> (node, server.node_rpc_config, body, response_handler_l, [& server = server]() {
server.stop ();
server.node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (3), [& io_ctx = server.node.alarm.io_ctx]() {
io_ctx.stop ();
});
}));
// For unsafe actions to be allowed, the unsafe encoding must be used AND the transport config must allow it
handler->process_request (allow_unsafe && config_transport.allow_unsafe);