Fix ipc server stop command
This commit is contained in:
parent
bc86e46624
commit
0c980bb247
4 changed files with 18 additions and 7 deletions
|
|
@ -277,9 +277,18 @@ public:
|
||||||
auto body (std::string (reinterpret_cast<char *> (buffer.data ()), buffer.size ()));
|
auto body (std::string (reinterpret_cast<char *> (buffer.data ()), buffer.size ()));
|
||||||
|
|
||||||
// Note that if the rpc action is async, the shared_ptr<json_handler> lifetime will be extended by the action handler
|
// 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] () {
|
auto handler (std::make_shared<nano::json_handler> (node, server.node_rpc_config, body, response_handler_l, [server_w = server.weak_from_this ()] () {
|
||||||
server.stop ();
|
|
||||||
// TODO: Previously this was stopping node.io_ctx, which was wrong. Investigate what's going on here. Why isn't it using stop_callback passed externally?
|
// TODO: Previously this was stopping node.io_ctx, which was wrong. Investigate what's going on here. Why isn't it using stop_callback passed externally?
|
||||||
|
// This is running on the IO thread, so attempting to directly stop the server will cause it to try joining itself.
|
||||||
|
// This RPC/IPC system is really badly designed...
|
||||||
|
std::thread ([server_w] () {
|
||||||
|
std::this_thread::sleep_for (std::chrono::seconds (1));
|
||||||
|
if (auto server = server_w.lock ())
|
||||||
|
{
|
||||||
|
server->stop ();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach ();
|
||||||
}));
|
}));
|
||||||
// For unsafe actions to be allowed, the unsafe encoding must be used AND the transport config must allow it
|
// 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);
|
handler->process_request (allow_unsafe && config_transport.allow_unsafe);
|
||||||
|
|
@ -600,6 +609,8 @@ nano::ipc::ipc_server::ipc_server (nano::node & node_a, nano::node_rpc_config co
|
||||||
nano::ipc::ipc_server::~ipc_server ()
|
nano::ipc::ipc_server::~ipc_server ()
|
||||||
{
|
{
|
||||||
node.logger.debug (nano::log::type::ipc_server, "Server stopped");
|
node.logger.debug (nano::log::type::ipc_server, "Server stopped");
|
||||||
|
|
||||||
|
stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::ipc::ipc_server::stop ()
|
void nano::ipc::ipc_server::stop ()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace ipc
|
||||||
{
|
{
|
||||||
class access;
|
class access;
|
||||||
/** The IPC server accepts connections on one or more configured transports */
|
/** The IPC server accepts connections on one or more configured transports */
|
||||||
class ipc_server final
|
class ipc_server final : public std::enable_shared_from_this<ipc_server>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ipc_server (nano::node & node, nano::node_rpc_config const & node_rpc_config);
|
ipc_server (nano::node & node, nano::node_rpc_config const & node_rpc_config);
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include <boost/property_tree/json_parser.hpp>
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
|
|
||||||
nano::test::rpc_context::rpc_context (std::shared_ptr<nano::rpc> & rpc_a, std::unique_ptr<nano::ipc::ipc_server> & ipc_server_a, std::unique_ptr<nano::ipc_rpc_processor> & ipc_rpc_processor_a, std::unique_ptr<nano::node_rpc_config> & node_rpc_config_a)
|
nano::test::rpc_context::rpc_context (std::shared_ptr<nano::rpc> & rpc_a, std::shared_ptr<nano::ipc::ipc_server> & ipc_server_a, std::unique_ptr<nano::ipc_rpc_processor> & ipc_rpc_processor_a, std::unique_ptr<nano::node_rpc_config> & node_rpc_config_a)
|
||||||
{
|
{
|
||||||
rpc = std::move (rpc_a);
|
rpc = std::move (rpc_a);
|
||||||
ipc_server = std::move (ipc_server_a);
|
ipc_server = std::move (ipc_server_a);
|
||||||
|
|
@ -45,7 +45,7 @@ bool nano::test::check_block_response_count (nano::test::system & system, rpc_co
|
||||||
nano::test::rpc_context nano::test::add_rpc (nano::test::system & system, std::shared_ptr<nano::node> const & node_a)
|
nano::test::rpc_context nano::test::add_rpc (nano::test::system & system, std::shared_ptr<nano::node> const & node_a)
|
||||||
{
|
{
|
||||||
auto node_rpc_config (std::make_unique<nano::node_rpc_config> ());
|
auto node_rpc_config (std::make_unique<nano::node_rpc_config> ());
|
||||||
auto ipc_server (std::make_unique<nano::ipc::ipc_server> (*node_a, *node_rpc_config));
|
auto ipc_server (std::make_shared<nano::ipc::ipc_server> (*node_a, *node_rpc_config));
|
||||||
nano::rpc_config rpc_config (node_a->network_params.network, system.get_available_port (), true);
|
nano::rpc_config rpc_config (node_a->network_params.network, system.get_available_port (), true);
|
||||||
const auto ipc_tcp_port = ipc_server->listening_tcp_port ();
|
const auto ipc_tcp_port = ipc_server->listening_tcp_port ();
|
||||||
debug_assert (ipc_tcp_port.has_value ());
|
debug_assert (ipc_tcp_port.has_value ());
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@ namespace test
|
||||||
class rpc_context
|
class rpc_context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rpc_context (std::shared_ptr<nano::rpc> & rpc_a, std::unique_ptr<nano::ipc::ipc_server> & ipc_server_a, std::unique_ptr<nano::ipc_rpc_processor> & ipc_rpc_processor_a, std::unique_ptr<nano::node_rpc_config> & node_rpc_config_a);
|
rpc_context (std::shared_ptr<nano::rpc> & rpc_a, std::shared_ptr<nano::ipc::ipc_server> & ipc_server_a, std::unique_ptr<nano::ipc_rpc_processor> & ipc_rpc_processor_a, std::unique_ptr<nano::node_rpc_config> & node_rpc_config_a);
|
||||||
|
|
||||||
std::shared_ptr<nano::rpc> rpc;
|
std::shared_ptr<nano::rpc> rpc;
|
||||||
std::unique_ptr<nano::ipc::ipc_server> ipc_server;
|
std::shared_ptr<nano::ipc::ipc_server> ipc_server;
|
||||||
std::unique_ptr<nano::ipc_rpc_processor> ipc_rpc_processor;
|
std::unique_ptr<nano::ipc_rpc_processor> ipc_rpc_processor;
|
||||||
std::unique_ptr<nano::node_rpc_config> node_rpc_config;
|
std::unique_ptr<nano::node_rpc_config> node_rpc_config;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue