From 437ad9b446715e02e35e1f07145f614f577f9745 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 18 Aug 2018 12:02:35 +0900 Subject: [PATCH] Handle flush races gracefully Fixes #552 I cannot see how these can occur other than during a reorg, but the submitter didn't seem to think there was a reorg. So log it and recover gracefully; let's see if many report these. --- electrumx/server/db.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/electrumx/server/db.py b/electrumx/server/db.py index 4c08497..9c1a55e 100644 --- a/electrumx/server/db.py +++ b/electrumx/server/db.py @@ -19,7 +19,7 @@ from glob import glob from struct import pack, unpack import attr -from aiorpcx import run_in_thread +from aiorpcx import run_in_thread, sleep import electrumx.lib.util as util from electrumx.lib.hash import hash_to_hex_str, HASHX_LEN @@ -438,7 +438,13 @@ class DB(object): fs_tx_hash = self.fs_tx_hash return [fs_tx_hash(tx_num) for tx_num in tx_nums] - return await run_in_thread(read_history) + while True: + history = await run_in_thread(read_history) + if all(hash is not None for hash, height in history): + return history + self.logger.warning(f'limited_history: tx hash ' + f'not found (reorg?), retrying...') + await sleep(0.25) # -- Undo information @@ -601,7 +607,13 @@ class DB(object): utxos_append(UTXO(tx_num, tx_pos, tx_hash, height, value)) return utxos - return await run_in_thread(read_utxos) + while True: + utxos = await run_in_thread(read_utxos) + if all(utxo.tx_hash is not None for utxo in utxos): + return utxos + self.logger.warning(f'all_utxos: tx hash not ' + f'found (reorg?), retrying...') + await sleep(0.25) async def lookup_utxos(self, prevouts): '''For each prevout, lookup it up in the DB and return a (hashX,