wallet: stop() to clean-up lnworker even in offline mode
What changed, and why it matters
This commit fixes a cleanup bug in Electrum wallet shutdown. Previously, the Lightning Network worker (lnworker) was only stopped when the wallet was online. If the wallet was offline, the Lightning worker might not shut down cleanly, potentially leaving background tasks running or resources not released. The change ensures the Lightning worker is always stopped during wallet shutdown, regardless of whether a network connection exists.
Apply the patch. It is a low-risk defensive fix that improves shutdown reliability. No immediate incident response is indicated unless further evidence shows the dangling lnworker caused exploitable behavior.
Security signals we found
Improper resource cleanup / shutdown sequence
Background task not terminated in offline mode
Lightning worker left running after wallet stop
Evidence from the diff
In Abstract_Wallet.stop(), the original code nested lnworker.stop() inside the if self.network: block. This meant that if self.network was None (offline mode), lnworker.stop() was never awaited and lnworker was not set to None. The patch moves the lnworker cleanup outside the network check, so it executes unconditionally. It also moves taskgroup.cancel_remaining() outside the network check, ensuring remaining tasks are cancelled even when offline. This is a resource-lifecycle and graceful-shutdown fix.
Changed components
electrum/wallet.pyAbstract_Wallet.stop()lnworkerInspect captured patch +4 / −3
diff --git a/electrum/wallet.py b/electrum/wallet.py
index c852603..ebc5292 100644
--- a/electrum/wallet.py
+++ b/electrum/wallet.py
@@ -562,11 +562,12 @@ class Abstract_Wallet(ABC, Logger, EventListener):
self.unregister_callbacks()
try:
async with ignore_after(5):
+ if self.lnworker:
+ await self.lnworker.stop()
+ self.lnworker = None
if self.network:
- if self.lnworker:
- await self.lnworker.stop()
- self.lnworker = None
self.network = None
+ if self.taskgroup:
await self.taskgroup.cancel_remaining()
self.taskgroup = None
await self.adb.stop()
Why this scored 29/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.