mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-25 22:11:17 +00:00
> This PR was investigated, written and opened by an AI agent acting autonomously on behalf of the fork owner. ## Problem On a host without IPv4 connectivity (for example an IPv6-only Kubernetes cluster that reaches IPv4 sites through NAT64/DNS64), every Anna's Archive search via the internal bypasser comes back empty and the AA mirrors get quarantined with "responded without an Anna's Archive page". The page the bypasser hands back is Chromium's own error page: ``` Search page has no results table: https://annas-archive.pk/search?... (bytes=252838, title='annas-archive.pk', aa_markers=none, challenge_marker=None, over_challenge_size_cap=True) ``` Its body is "This site can't be reached ... ERR_ADDRESS_UNREACHABLE". Because it is over the 64 KB challenge cap and carries no AA markers, it is classified as "not AA" and the mirror is rotated/quarantined, so the user only ever sees "No books found". ## Cause `_build_host_resolver_rules` pre-resolves AA hostnames with `socket.getaddrinfo(hostname, 443, socket.AF_INET)` and pins the result into Chrome with `--host-resolver-rules=MAP <host> <ip>`. Forcing `AF_INET` returns the raw A record even when the system resolver would hand back a reachable address: ``` annas-archive.pk AF_INET: 186.2.163.174 | default: 64:ff9b::ba02:a3ae ``` So Chrome is told to connect to an IPv4 address the host has no route to. Plain `requests` traffic is unaffected because it uses the default lookup. ## Fix Resolve without restricting the address family and use the first address the system resolver returns, bracketing IPv6 literals as Chrome's `MAP` rule syntax requires. Behaviour on IPv4 hosts is unchanged (the first result is still the A record there). ## Verification - New unit test `test_host_resolver_rules_use_the_system_resolvers_address_family` covers both an IPv6 (NAT64) and an IPv4 answer; it fails on `main` and passes with the fix. - `pytest tests/ -m "not integration and not e2e"`: 6110 passed. `ruff check`, `ruff format --check` and `basedpyright` (source and tests) are clean. - End to end on the affected IPv6-only deployment (v1.5.1 image, with the patched function applied in-process): Chrome reached `annas-archive.pk`, the DDoS-Guard challenge cleared itself, and the returned page was `Elantris - Search - Anna's Archive` with a results table. Before the patch the same call returned the `ERR_ADDRESS_UNREACHABLE` page. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved host resolution to support IPv6 addresses alongside IPv4 when configuring browser connections. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Joshua Tag Howard <git@jthoward.dev>