Skip to content

Commit

Permalink
Retry on ChunkedEncodingError; Break loop on all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Apr 27, 2024
1 parent e830323 commit a93f65a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions counterparty-core/counterpartycore/lib/backend/addrindexrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import bitcoin.wallet
import requests
from pkg_resources import parse_version # noqa: F401
from requests.exceptions import ConnectionError, ReadTimeout, Timeout
from requests.exceptions import ChunkedEncodingError, ConnectionError, ReadTimeout, Timeout

Check warning

Code scanning / pylint

Redefining built-in 'ConnectionError'. Warning

Redefining built-in 'ConnectionError'.

from counterpartycore.lib import config, exceptions, ledger, util

Expand Down Expand Up @@ -53,6 +53,7 @@ def rpc_call(payload):
response = None

tries = 0
broken_error = None
while True:
try:
tries += 1
Expand Down Expand Up @@ -86,11 +87,16 @@ def rpc_call(payload):
except KeyboardInterrupt:
logger.warning("Interrupted by user")
exit(0)
except (Timeout, ReadTimeout, ConnectionError):
except (Timeout, ReadTimeout, ConnectionError, ChunkedEncodingError):
logger.debug(
f"Could not connect to backend at `{util.clean_url_for_log(url)}`. (Try {tries})"
)
time.sleep(5)
except Exception as e:

Check warning

Code scanning / pylint

Catching too general exception Exception. Warning

Catching too general exception Exception.
broken_error = e
break
if broken_error:
raise broken_error

# Handle json decode errors
try:
Expand Down

0 comments on commit a93f65a

Please sign in to comment.