Commit message · Sasha Zykovhw_wallet: fix crash on exit if device unpairing fails
On wallet close, the close_wallet hook unpaired the device before
stopping the keystore TaskThread. Unpairing does device I/O and can
raise, e.g. if the device was unplugged while the wallet was open:
Plugin error. plugin: trezor, hook: close_wallet
Traceback (most recent call last):
File "electrum/plugin.py", line 833, in run_hook
r = f(*args)
File "electrum/hw_wallet/plugin.py", line 89, in close_wallet
self.device_manager().unpair_pairing_code(keystore.pairing_code())
File "electrum/plugin.py", line 1118, in unpair_pairing_code
self._close_client(_id)
File "electrum/plugin.py", line 1134, in _close_client
client.close()
...
File "electrum/plugins/trezor/clientbase.py", line 286, in close
self.client.lock()
...
trezorlib.transport.bridge.BridgeException: trezord: acquire/62/null failed with code 400: device not found
run_hook() swallows the exception, so the thread was never stopped.
A still-running QThread (child of the wallet window) at interpreter
shutdown then makes Qt abort the process:
QThread: Destroyed while thread '' is still running
Stop the thread before unpairing, and make DeviceMgr._close_client
treat client.close() as best-effort, as closing a missing device is
a normal condition during cleanup.
73/100 · AdequateMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
Why it was queuedsigning or wallet pathsecond-pass: broader security terminologysecond-pass: security-sensitive path
AI analysis · Low 29/100This commit fixes a crash that could happen when closing an Electrum wallet that uses a hardware device (like a Trezor). If the device was unplugged before closing, the wallet's cleanup step could fail and leave a background Qt thread running. At shutdown, Qt would then forcefully abort the whole program. The fix stops the thread first and treats device-close failures as harmless during cleanup.