mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
ipc: Avoid waiting for clients to disconnect when shutting down
This fixes behavior reported by Antoine Poinsot <darosior@protonmail.com> https://github.com/bitcoin/bitcoin/pull/29409#issuecomment-2546088852 where if an IPC client is connected, the node will wait forever for it to disconnect before exiting.
This commit is contained in:
parent
cf1c26a3a2
commit
8ca7049cea
5 changed files with 23 additions and 0 deletions
|
@ -398,6 +398,12 @@ void Shutdown(NodeContext& node)
|
||||||
|
|
||||||
RemovePidFile(*node.args);
|
RemovePidFile(*node.args);
|
||||||
|
|
||||||
|
// If any -ipcbind clients are still connected, disconnect them now so they
|
||||||
|
// do not block shutdown.
|
||||||
|
if (interfaces::Ipc* ipc = node.init->ipc()) {
|
||||||
|
ipc->disconnectIncoming();
|
||||||
|
}
|
||||||
|
|
||||||
LogPrintf("%s: done\n", __func__);
|
LogPrintf("%s: done\n", __func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,9 @@ public:
|
||||||
//! using provided callback. Throws an exception if there was an error.
|
//! using provided callback. Throws an exception if there was an error.
|
||||||
virtual void listenAddress(std::string& address) = 0;
|
virtual void listenAddress(std::string& address) = 0;
|
||||||
|
|
||||||
|
//! Disconnect any incoming connections that are still connected.
|
||||||
|
virtual void disconnectIncoming() = 0;
|
||||||
|
|
||||||
//! Add cleanup callback to remote interface that will run when the
|
//! Add cleanup callback to remote interface that will run when the
|
||||||
//! interface is deleted.
|
//! interface is deleted.
|
||||||
template<typename Interface>
|
template<typename Interface>
|
||||||
|
|
|
@ -68,6 +68,13 @@ public:
|
||||||
m_loop->loop();
|
m_loop->loop();
|
||||||
m_loop.reset();
|
m_loop.reset();
|
||||||
}
|
}
|
||||||
|
void disconnectIncoming() override
|
||||||
|
{
|
||||||
|
if (!m_loop) return;
|
||||||
|
m_loop->sync([&] {
|
||||||
|
m_loop->m_incoming_connections.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) override
|
void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) override
|
||||||
{
|
{
|
||||||
mp::ProxyTypeRegister::types().at(type)(iface).cleanup_fns.emplace_back(std::move(cleanup));
|
mp::ProxyTypeRegister::types().at(type)(iface).cleanup_fns.emplace_back(std::move(cleanup));
|
||||||
|
|
|
@ -86,6 +86,10 @@ public:
|
||||||
int fd = m_process->bind(gArgs.GetDataDirNet(), m_exe_name, address);
|
int fd = m_process->bind(gArgs.GetDataDirNet(), m_exe_name, address);
|
||||||
m_protocol->listen(fd, m_exe_name, m_init);
|
m_protocol->listen(fd, m_exe_name, m_init);
|
||||||
}
|
}
|
||||||
|
void disconnectIncoming() override
|
||||||
|
{
|
||||||
|
m_protocol->disconnectIncoming();
|
||||||
|
}
|
||||||
void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) override
|
void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) override
|
||||||
{
|
{
|
||||||
m_protocol->addCleanup(type, iface, std::move(cleanup));
|
m_protocol->addCleanup(type, iface, std::move(cleanup));
|
||||||
|
|
|
@ -58,6 +58,9 @@ public:
|
||||||
//! clients and servers independently.
|
//! clients and servers independently.
|
||||||
virtual void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) = 0;
|
virtual void serve(int fd, const char* exe_name, interfaces::Init& init, const std::function<void()>& ready_fn = {}) = 0;
|
||||||
|
|
||||||
|
//! Disconnect any incoming connections that are still connected.
|
||||||
|
virtual void disconnectIncoming() = 0;
|
||||||
|
|
||||||
//! Add cleanup callback to interface that will run when the interface is
|
//! Add cleanup callback to interface that will run when the interface is
|
||||||
//! deleted.
|
//! deleted.
|
||||||
virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
|
virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue