crt/crt_db error handling#3124
Open
liquidsec wants to merge 3 commits into
Open
Conversation
- crt: override _api_response_is_success so 404 falls back to api_request's retry path instead of being treated as "no data" (crt.sh returns 404/503 transiently when overloaded). Co-authored with @TrebledJ's #3077. - crt_db: reconnect when the asyncpg connection is dropped mid-scan, and bail out via set_error_state on Postgres OutOfMemoryError instead of hammering the upstream.
Contributor
🚀 Performance Benchmark Report
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #3124 +/- ##
=====================================
- Coverage 90% 90% -0%
=====================================
Files 441 441
Lines 38743 38781 +38
=====================================
+ Hits 34663 34695 +32
- Misses 4080 4086 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Supersedes #3077 — bundles the fix @TrebledJ proposed there with an adjacent fix in
crt_dbthat came out of the same audit.crt: don't short-circuit 404 as "no data"
The default
_api_response_is_successinBaseModuletreats HTTP 404 as success because most APIs use 404 to mean "no records for this query." crt.sh's API returns 404 (and 503) transiently when overloaded — it's a real failure, not an empty-set signal. Today those responses pass through_api_response_is_success, skip the api_request retry loop, hitparse_results, and produceJSONDecodeErrornoise.This overrides the success check in the crt module to drop the 404 special case:
So 404 → counts as a failure → api_request retries with backoff → if still failing after
api_failure_abort_threshold, the module enters error state (same path 503 already takes).Credit to @TrebledJ for spotting this in #3077; this PR uses the corrected logic from the review there (#3077's diff inverted the membership check and unintentionally promoted 400/500/502/etc. to success — sending the abort threshold the wrong way).
crt_db: reconnect on dropped connections, bail on Postgres OOM
A real bbot scan log shows two flavors of repeating failure from
crt_db:asyncpg.InterfaceError: connection is closeddb_conn.fetch()raises and the module is silently broken for the rest of the scan with no recovery path.asyncpg.OutOfMemoryErrorThe fix:
_connect()so the same parameters can be reused.db_conn is None or db_conn.is_closed()and reopen.fetch()soInterfaceError/ConnectionErrorclearsself.db_conn(next call reconnects) and re-raises.OutOfMemoryError, callset_error_state(...)so the module backs off cleanly for the rest of the scan.Added a regression test
TestCRT_DB_Reconnectthat drops the first connection mid-scan and asserts the module reconnects and continues producing results.