fix(safe): retry Safe API transport errors instead of crashing#275
Merged
Conversation
get_safe_transactions() retried on HTTP 429/5xx but let transport-level failures (connection reset, read timeout, DNS) propagate uncaught, crashing the safe monitor with a bare requests.ConnectionError that surfaces as a "[yearn] main crashed" Telegram alert. Wrap the request in the existing backoff/retry loop and add a 10s timeout, mirroring get_safe_current_nonce()'s graceful handling. After exhausting retries it returns [] (existing fall-through) instead of aborting the whole run. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
73fd434 to
5fbd73a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
get_safe_transactions()inprotocols/safe/main.pyretried on HTTP 429/5xx status codes but let transport-level failures (ConnectionResetError, read timeouts, DNS) propagate uncaught. Therequests.getalso had no timeout.A reset on the Safe Transaction Service (
api.safe.global) therefore crashed the wholesafemonitor with a barerequests.exceptions.ConnectionError, surfacing as:The sibling
get_safe_current_nonce()already wraps its call in try/except +timeout=10and degrades gracefully; this bringsget_safe_transactions()in line.How
requests.getin the existingmax_retriesbackoff loop, catchingrequests.exceptions.RequestException(covers connection reset / timeout / DNS) and retrying with the same exponential backoff used for 429/5xx.timeout=10, matchingget_safe_current_nonce().return []instead of aborting the run.Why it matters
The
safetask is long-running (often 150–230s, paginated across 6 networks), so a mid-run socket reset againstapi.safe.globalis an expected transient. It should retry, not page the alerts channel and skip the rest of the multisig sweep.Testing
uv run pytest tests/→ 476 passed, 4 skippeduv run ruff check ./ruff format --check→ cleantests/test_safe_main.py:ConnectionErrorthen succeeds (2 calls, 1 backoff sleep)[]after exhaustingmax_retries🤖 Generated with Claude Code