AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 29 Bitcoin

hw_wallet: fix crash on exit if device unpairing fails

Public commit record

What the developer wrote

Authored by Sasha Zykov

73/100 · Adequate
hw_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.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This 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.

Recommended action

Apply the patch. It is a low-risk defensive fix that prevents a reproducible crash during wallet shutdown when a hardware wallet is disconnected. No immediate incident response is required beyond normal patching.

Security signals we found

01

Denial-of-service via abnormal process termination (Qt abort) on wallet close

02

Unhandled exception in cleanup hook leading to resource leak (QThread)

03

Best-effort handling added for device I/O failures during teardown

Risk score

Why this scored 29/100

Our methodology →
Potential impact 8/30
Exploitability 2/25
Stealth signal 3/15
Affected reach 5/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.