Skip to content

fix(traffic): wait a few minutes before reading a failed bot range list again - #1251

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/bot-range-retry
Oct 20, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/bot-range-retry

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Follow-up from #1179's review (not blocking there): "Range-file retries: in ai-bots.js, a range file that fails to load is fetched again for every request with that bot's user agent, one after another, with a 10 s timeout each. Caching the failure for a few minutes and sharing the in-flight fetch avoids that."

Before: with no list ever read, a failed fetch cached nothing. verifyRequests checks a batch's requests in turn, so a Worker batch of 100 GPTBot requests during an OpenAI outage could wait 100 × 10 s.

Now (server/src/lib/ai-bots.js, rangesFor)

  • A failed first read is remembered for RANGES_RETRY_MS (5 minutes). Until then that bot's requests read as no_ranges at once, as they already did after the wait.
  • Requests that need a list being read share that one fetch (pending map).
  • A failed refresh still keeps the last list for an hour, as before.
  • The cache entries now hold until instead of at, so the three cases share one check.

Related issue

Follow-up to #1179.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Unit tests (ai-bots.test.js). Both new ones fail on the old code:

  • a failed first read isn't fetched again before RANGES_RETRY_MS, then is;
  • three concurrent reads share one fetch and one list.

Against a real timeout: a script calling the branch's rangesFor for an unroutable address (https://10.255.255.1/ranges.json, so the real fetch waits out its 10 s):

  • five concurrent requests took 10.0 s with 1 fetch;
  • the next request returned null in 0.00 s with no new fetch.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — web not touched
  • yarn typecheck passes (run from web/) — web not touched
  • yarn format:check passes (run from web/) — web not touched
  • Changes are focused — one concern per PR

Server: npm run format, npm run lint, npm test (1841) pass.

🤖 Generated with Claude Code

…st again

A bot's published IP range list that had never loaded was fetched again
for every request with that bot's user agent, and a batch verifies its
requests one after another, so each waited out the 10 s timeout in turn.
After a failed first read the list is now tried again only after
RANGES_RETRY_MS (5 minutes), and requests that need a list being read
share that one read. A failed refresh still keeps the last list for an
hour.

Follow-up to ansvisor#1179's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk the range-file note from #1179: a failed first read is now remembered for 5 minutes, and concurrent requests share the fetch under way. Checked against a real 10 s timeout: five concurrent requests made one fetch, and the next one returned at once. The generated Worker note (passThroughOnException, secret binding, origin + pathname) comes next as its own PR.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Remembering a failed first read for a few minutes and sharing the read in flight fixes the 100 × 10 s case.

Optional, for later: once a day, when a list is older than its TTL and a refresh is under way, requests wait for that refresh even though a usable list is still in memory. Returning the stale list right away while the refresh runs would remove that wait.

@gkhngyk
gkhngyk merged commit d101993 into ansvisor:main Oct 20, 2026
6 checks passed
gkhngyk pushed a commit that referenced this pull request Oct 20, 2026
Once a day, when a range list was past its TTL, the requests that needed
it waited for the refresh even though a usable list was still in memory.
They now use that list at once while the one shared read runs; only a
request with no list to use waits for it.

Follow-up to gkhngyk's note on #1251.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants