Skip to content

Retry a timed-out mainland China host only through a mainland-exit proxy - #101

Merged
Digidai merged 5 commits into
mainfrom
mainland-exit-proxy
Nov 21, 2026
Merged

Digidai merged 5 commits into
mainfrom
mainland-exit-proxy

Conversation

@Digidai

@Digidai Digidai commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

What changes

A mainland China host (.cn) whose direct fetch times out is now retried through a proxy only when PROXY_POOL_MAINLAND names proxies that exit in mainland China, and the retry goes through those. Without that setting the request fails after the 10-second direct timeout, as it did before #100.

The 504 message now reads: "The site did not answer. Many sites hosted in mainland China, especially government and university sites, only answer visitors inside mainland China."

Details:

  • The proxy follows the hop that timed out. A mainland host goes to the mainland proxies only. A redirect target outside mainland China keeps the general proxy and the general timeout message.
  • The mainland proxies keep their own record of hosts that refused them (a bot wall or 429 on every attempt), apart from the general proxy's. Either record covers the host's root-dot spelling too.
  • An anonymous mainland retry spends no proxy budget when no mainland proxy is configured.
  • A host named with its root dot (www.example.gov.cn.) counts as a mainland host, and the proxy's TLS handshake checks the certificate against the name without the dot.
  • Attempts through the mainland proxies are counted as proxy_pool_mainland, apart from proxy_pool, so the failure alert judges each pool on its own. /admin shows them on their own card, off until PROXY_POOL_MAINLAND is set.

Why

#100 retried these hosts through the general proxy, on the premise that they answer a home connection abroad. That premise was wrong: the machine used to check it reaches mainland sites from a mainland address.

Measured on the 57 mainland hosts that timed out between 2026-11-01 and 2026-11-21 (281 timeouts):

TCP reachability from 14 probe locations abroad Hosts Timeouts
None connect 23 140
Only one to three connect (Hong Kong, Japan) 7 45
Most connect 15 84
Not probed (one timeout each) 12 12
  • All six retries in production since Retry a timed-out mainland China fetch once through the proxy #100 deployed timed out on both attempts, including two hosts from the "most connect" group, over both http and https.
  • Each failed request therefore waited about 20 seconds longer for the same 504, and an anonymous one spent a unit of the daily proxy budget.

Not fixed here

  • No mainland-exit proxy is configured, so these hosts still fail. This change makes the failure fast again and leaves the retry ready for one.
  • The proxy path speaks TLS 1.3 only. 15 of the 31 https hosts probed offer TLS 1.2 at most, so a mainland exit will not reach those over https.
  • The /admin card for the mainland proxies has no connection test. A probe needs a real mainland exit to validate against.
  • A URL outside .cn that redirects to a mainland host which then times out is not retried, as on main: it has already waited 30 seconds.
  • The gaps listed in Retry a timed-out mainland China fetch once through the proxy #100 remain.

Verification

  • npx vitest run: 949 tests pass.
  • "skips the proxy for that host for a day after a challenge, and only for that host" fails when the root-dot spelling gets its own record. Typecheck passes for the Worker and web/.
  • "does not retry through a proxy that exits abroad" (anonymous and signed-in, only the general proxy configured) fails when the retry is pointed at the general pool or may fall back to PROXY_URL.
  • "retries a redirect target outside mainland China through the general proxy, not the mainland one" fails when every hop goes to the mainland pool, when a failed non-mainland hop gets the mainland message, and when a timeout that fired mid retry backoff is reported as 502.
  • "keeps the mainland proxy's refused hosts apart from the general proxy's" fails with one shared record.
  • Two tests fail when mainland attempts are counted as proxy_pool.
  • "checks the certificate against the host without its root dot" fails when the dot is kept.
  • Not covered by a test: the root-dot host classification and the budget check for an unparsable mainland pool.

The retry added in #100 went through the general proxy, which exits abroad.
The hosts it targets answer only addresses inside mainland China: of 45 that
timed out in November, 30 dropped connections from nearly every probe location
abroad, and all six production retries timed out. Each failed request waited
20 seconds longer for the same 504 and an anonymous one spent proxy budget.

The retry now runs only when PROXY_POOL_MAINLAND names proxies that exit in
mainland China, and goes through those. Without it the request fails after
the 10-second direct timeout. The error message says the site answers only
visitors inside mainland China.

Amp-Thread-ID: https://ampcode.com/threads/T-01a19236-e961-759a-a320-167408397ed5
Co-authored-by: Amp <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-21T11:37:09.903495Z
We couldn’t complete this review. Comment @codex review to try again.
77e1cd1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Digidai

Digidai commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
website2markdown 756e9e1 Nov 21 2026, 12:01 PM

Digidai and others added 4 commits November 21, 2026 19:44
A host that turned the general proxy away could skip the mainland proxy for a
day, because both shared one record. Each pool now keeps its own.

A mainland URL that redirects to a host outside mainland China, which then
times out, is no longer sent to the mainland proxy.
The pool now follows the hop that timed out: a mainland host goes to the
mainland proxies only, any other redirect target keeps the general proxy and
the general timeout message.

An anonymous mainland retry no longer spends budget when no mainland proxy
parses, a host named with its root dot counts as mainland, and /admin no
longer lists the mainland pool under the general proxy's card.
… apart

A mainland URL that redirects abroad, times out mid retry backoff and also
fails through the general proxy answered 502 target_unreadable. It is a
timeout: 504 target_timeout again.

Attempts through the mainland proxies are recorded as proxy_pool_mainland, so
one pool's failures do not hide in the other's rate, and /admin shows them on
their own card (off until PROXY_POOL_MAINLAND is set).

The proxy's TLS handshake checks the certificate against the host without its
root dot.
A site that refused the proxy was tried again, and spent anonymous budget
again, when the same host was written with its root dot.

Amp-Thread-ID: https://ampcode.com/threads/T-01a19236-e961-759a-a320-167408397ed5
Co-authored-by: Amp <[email protected]>
@Digidai
Digidai merged commit e197ea3 into main Nov 21, 2026
2 checks passed
@Digidai
Digidai deleted the mainland-exit-proxy branch November 21, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant