spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.4k stars 3.08k forks source link

on `init_lightning`, `wallet.taskgroup` dies and never recovers #8301

Closed SomberNight closed 1 year ago

SomberNight commented 1 year ago

Enabling lightning, e.g. for a watch-only wallet, leaves the wallet in a bugged state until reopening it or restarting.

Taskgroups are not reusable. wallet.taskgroup is set in init and nowhere else atm. https://github.com/spesmilo/electrum/blob/8774e5934703ed156e3ea14ad7012acfc4168d84/electrum/wallet.py#L330

This stop/start_network logic, especially without awaiting in between, does not work: https://github.com/spesmilo/electrum/blob/8774e5934703ed156e3ea14ad7012acfc4168d84/electrum/wallet.py#L440-L444

See https://github.com/spesmilo/electrum/commit/bf6ecb64182b424a072112e36f5738eaf8cd64b9

The failure is invisible to the user, unless they are looking at the log, but the taskgroup dies.

  8.19 | I | synchronizer.[wallet_4] | receiving history bcrt1qndaru6pfal030ev296uxwuulxrezaj0juxp59s 1
  8.20 | I | synchronizer.[wallet_4] | receiving history bcrt1qlclgzsp2tktdl66xuk3je7ztztstxvjafka2ed 1
  8.20 | I | synchronizer.[wallet_4] | receiving history bcrt1qtqqddqrlg4xj3dzvjnea8wh5zy2fdf3jyk8dqe 1
  8.20 | I | synchronizer.[wallet_4] | receiving history bcrt1qsd2c4xwg47hnngn2uqg66y5rxz2hp0747v6dd2 2
  8.20 | I | synchronizer.[wallet_4] | receiving history bcrt1q9u3ufsm9ksql8utguap40ch8zpnw83fgqqv0jh 1
  8.25 | I | gui.qt.main_window.[wallet_4] | using default geometry
  8.28 | D | util.profiler | Deterministic_Wallet.try_detecting_internal_addresses_corruption 0.0197 sec
  8.28 | D | util.profiler | ElectrumWindow.load_wallet 0.0454 sec
  8.44 | I | storage.WalletStorage | saved /home/user/.electrum/regtest/wallets/wallet_4
  8.44 | D | util.profiler | WalletDB._write 0.0108 sec
  8.44 | I | w/wallet.Standard_Wallet.[wallet_4] | set_up_to_date: True
  8.44 | D | util.profiler | WalletDB._write 0.0000 sec
  8.44 | D | util.profiler | WalletDB._write 0.0000 sec
  8.53 | D | util.profiler | WalletDB._write 0.0000 sec
  8.65 | I | gui.qt.update_checker.UpdateCheckThread | valid sig for version announcement '4.3.4' from address '13xjmVAB1EATPP8RshTE8S8sNwwSUM9p1P'
  8.82 | I | gui.qt.history_list.HistoryModel | refreshing... reason: update_tabs
  8.83 | D | util.profiler | Abstract_Wallet.get_full_history 0.0090 sec
  8.83 | D | util.profiler | HistoryModel.refresh 0.0149 sec
  8.84 | D | util.profiler | AddressList.update 0.0000 sec
  8.84 | D | util.profiler | Abstract_Wallet.get_full_history 0.0027 sec
 10.15 | I | gui.qt.ElectrumGui | starting Qt main loop

 15.87 | I | w/wallet.Standard_Wallet.[wallet_4] | taskgroup stopped.
 15.88 | I | storage.WalletStorage | saved /home/user/.electrum/regtest/wallets/wallet_4
 15.88 | D | util.profiler | WalletDB._write 0.0150 sec
 15.89 | I | w/wallet.Standard_Wallet.[wallet_4] | starting taskgroup.
 15.89 | E | w/wallet.Standard_Wallet.[wallet_4] | taskgroup died.
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/wallet.py", line 371, in main_loop
    await group.spawn(asyncio.Event().wait)  # run forever (until cancel)
  File "/home/user/wspace/electrum/packages/aiorpcx/curio.py", line 204, in spawn
    self._add_task(task)
  File "/home/user/wspace/electrum/packages/aiorpcx/curio.py", line 150, in _add_task
    raise RuntimeError('task group terminated')
RuntimeError: task group terminated
 15.89 | I | w/wallet.Standard_Wallet.[wallet_4] | taskgroup stopped.
 15.89 | I | lnworker.LNWallet.[wallet_4] | starting taskgroup.
 15.91 | E | asyncio | Task was destroyed but it is pending!
task: <Task pending name='Task-379' coro=<Event.wait() done, defined at /usr/lib/python3.10/asyncio/locks.py:201> wait_for=<Future pending cb=[Task.task_wakeup()]>>
SomberNight commented 1 year ago

The failure is invisible to the user, unless they are looking at the log, but the taskgroup dies.

I've changed this in https://github.com/spesmilo/electrum/commit/488dc4871e3d10f5a59bc0b4a9e727f4df26a34c

SomberNight commented 1 year ago

closed by https://github.com/spesmilo/electrum/pull/8307