From a29258f8f1655b2e44df4f1be1ed587762c71b1c Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 17 Sep 2026 16:00:13 +0000 Subject: [PATCH] =?UTF-8?q?handle=20the=20monero-wallet-rpc=20random=20?= =?UTF-8?q?=E2=80=98stop=5Fwallet=E2=80=99=20connection=20closing=20regres?= =?UTF-8?q?sion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mmgen/proto/xmr/rpc.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/mmgen/proto/xmr/rpc.py b/mmgen/proto/xmr/rpc.py index 17a9bc89..7fc5edb5 100755 --- a/mmgen/proto/xmr/rpc.py +++ b/mmgen/proto/xmr/rpc.py @@ -12,7 +12,7 @@ proto.xmr.rpc: Monero base protocol RPC client class """ -import re +import os, re from ...rpc.local import RPCClient from ...rpc.util import IPPort, auth_data @@ -133,13 +133,23 @@ class MoneroWalletRPCClient(MoneroRPCClient): NB: the 'stop_wallet' RPC call closes the open wallet before shutting down the daemon, returning an error if no wallet is open """ + from requests.exceptions import ConnectionError + from ...util import ymsg try: return self.call('stop_wallet') - except Exception as e: - from ...util import msg, msg_r, ymsg - from ...color import yellow - msg(f'{type(e).__name__}: {e}') - msg_r(yellow('Unable to shut down wallet daemon gracefully, so killing process instead...')) - ret = self.daemon.stop(silent=True) - ymsg('done') - return ret + except ConnectionError as e: + # Handle the monero-wallet-rpc random connection closing regression with ‘stop_wallet’: + if 'closed connection' in str(e): + if self.daemon.use_pidfile: + try: + os.waitid(os.P_PID, int(self.daemon.pid), os.WEXITED|os.WNOHANG) # noqa ASYNC222 + # The daemon really did stop, so skip the warning and return: + except ChildProcessError: + return True + ymsg('Wallet daemon hung up unexpectedly, killing process just in case') + else: + ymsg(f'{type(e).__name__}: {e}') + except Exception: + ymsg('Unable to shut down wallet daemon gracefully, so killing process instead') + + return self.daemon.stop(silent=True)