Browse Source
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
they take locks in differing orders and are called from gui/network threads.
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
2 additions and
2 deletions
electrum/blockchain.py
@ -86,7 +86,7 @@ def hash_raw_header(header: str) -> str:
# key: blockhash hex at forkpoint
# key: blockhash hex at forkpoint
# the chain at some key is the best chain that includes the given hash
# the chain at some key is the best chain that includes the given hash
blockchains = { } # type: Dict[str, Blockchain]
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 ' ) :
def read_blockchains ( config : ' SimpleConfig ' ) :
@ -222,7 +222,7 @@ class Blockchain(Logger):
def get_parent_heights ( self ) - > Mapping [ ' Blockchain ' , int ] :
def get_parent_heights ( self ) - > Mapping [ ' Blockchain ' , int ] :
""" Returns map: (parent chain -> height of last common block) """
""" Returns map: (parent chain -> height of last common block) """
with blockchains_lock :
with self . lock , blockchains_lock :
result = { self : self . height ( ) }
result = { self : self . height ( ) }
chain = self
chain = self
while True :
while True :