ipc: Handle bitcoin-wallet disconnections

This fixes an error reported by Antoine Poinsot <darosior@protonmail.com> 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.
This commit is contained in:
Ryan Ofsky
2025-04-24 15:20:58 -04:00
parent 2160995916
commit 2581258ec2

View File

@@ -33,6 +33,7 @@
#include <interfaces/ipc.h>
#include <interfaces/mining.h>
#include <interfaces/node.h>
#include <ipc/exception.h>
#include <kernel/caches.h>
#include <kernel/context.h>
#include <key.h>
@@ -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.