From 2581258ec200efb173ea6449ad09b2e7f1cc02e0 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 24 Apr 2025 15:20:58 -0400 Subject: [PATCH] ipc: Handle bitcoin-wallet disconnections This fixes an error reported by Antoine Poinsot in https://github.com/bitcoin-core/libmultiprocess/issues/123 that does not happen in master, but does happen with https://github.com/bitcoin/bitcoin/pull/10102 applied, where if the child bitcoin-wallet process is killed (either by an external signal or by Ctrl-C as reported in the issue) the bitcoin-node process will not shutdown cleanly after that because chain client stop() calls will fail. This change fixes the problem by handling ipc::Exception errors thrown during the stop() calls, and it relies on the fixes to disconnect detection implemented in https://github.com/bitcoin-core/libmultiprocess/pull/160 to work effectively. --- src/init.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index cae52675525..7952495c093 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -298,6 +299,14 @@ void Shutdown(NodeContext& node) StopREST(); StopRPC(); StopHTTPServer(); + for (auto& client : node.chain_clients) { + try { + client->stop(); + } catch (const ipc::Exception& e) { + LogDebug(BCLog::IPC, "Chain client did not disconnect cleanly: %s", e.what()); + client.reset(); + } + } StopMapPort(); // Because these depend on each-other, we make sure that neither can be @@ -370,9 +379,6 @@ void Shutdown(NodeContext& node) } } } - for (const auto& client : node.chain_clients) { - client->stop(); - } // If any -ipcbind clients are still connected, disconnect them now so they // do not block shutdown.