electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit fa1762792a5bb5b9056b0fa6565a15138086fc1e
parent 2057185aa48d5157db9a07081a891e74dc7023c4
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 10 Feb 2021 19:40:10 +0100

lntransport: CancelledError needs priority over LPConnClosed

Scenario (prior this change):
A task in lnpeer.Peer.taskgroup raises ORIG_EXC, e.g. in htlc_switch.
The taskgroup then cancels all its tasks and then awaits each (in cancel_remaining):
https://github.com/kyuupichan/aiorpcX/blob/4e64c560422b1fc1dcebc2f926f4b74894e34cdf/aiorpcx/curio.py#L217-L221
In Peer.main_loop, we would want ORIG_EXC to be raised,
but instead LightningPeerConnectionClosed() will be raised as
the Peer._message_loop() task is cancelled, and it is awaited first in cancel_remaining.
We should make sure that if a task is cancelled it will let the CancelledError
propagate out, or at least it does not raise a different exception instead.

Diffstat:
Melectrum/lntransport.py | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/electrum/lntransport.py b/electrum/lntransport.py @@ -123,7 +123,9 @@ class LNTransportBase: break try: s = await self.reader.read(2**10) - except: + except asyncio.CancelledError: + raise + except Exception: s = None if not s: raise LightningPeerConnectionClosed()