tblockchain.py: maybe fix rare deadlock - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
DIR commit 4acf884790b2136dcff7948e975460f11cf0aa93
DIR parent 36178df875eef5186b9c25622b7b5ae345776ecf
HTML Author: SomberNight <somber.night@protonmail.com>
Date: Tue, 25 Aug 2020 20:29:08 +0200
blockchain.py: maybe fix rare deadlock
Saw a deadlock near a swap_with_parent(), could not reproduce.
get_branch_size() and get_parent_heights() could have been the culprits as
tthey take locks in differing orders and are called from gui/network threads.
Diffstat:
M electrum/blockchain.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
---
DIR diff --git a/electrum/blockchain.py b/electrum/blockchain.py
t@@ -86,7 +86,7 @@ def hash_raw_header(header: str) -> str:
# key: blockhash hex at forkpoint
# the chain at some key is the best chain that includes the given hash
blockchains = {} # type: Dict[str, Blockchain]
-blockchains_lock = threading.RLock()
+blockchains_lock = threading.RLock() # lock order: take this last; so after Blockchain.lock
def read_blockchains(config: 'SimpleConfig'):
t@@ -222,7 +222,7 @@ class Blockchain(Logger):
def get_parent_heights(self) -> Mapping['Blockchain', int]:
"""Returns map: (parent chain -> height of last common block)"""
- with blockchains_lock:
+ with self.lock, blockchains_lock:
result = {self: self.height()}
chain = self
while True: