Anti-abuse code that burned the Durable Objects allowance: heartbeats, rejected requests and D1 scans
Frank Zeng (@frankzeng2020) says an AI-written anti-abuse module pushed Durable Objects to 1.19 million requests against the 1 million included each month, costing him an extra $0.15; a budget alert email caught it, and the audit also found a D1 query path scanning 925 million rows a day and a signing key re-imported on every request. He shares a read-only self-audit prompt.
- Products
- Durable ObjectsD1Workers
- Source
- Author experience𝕏 post
- Author
- @frankzeng2020
Key points
- He says the anti-abuse module worked until an alert email arrived: Durable Objects had run 1.19 million times against a 1 million monthly allowance, and he paid an extra $0.15.
- Cause he reports: the player page sent a heartbeat and online count every 30 seconds that called a Durable Object 5 times, and even rejected requests passed through a Durable Object for the block check; one open page used about 430,000 calls a month, so three people keeping tabs open would use the whole month's allowance.
- His fixes: move the heartbeat out of the Durable Object, cache rejections at the edge, merge quota checks and add degradation/circuit breaking.
- Other findings he lists: a low-frequency crawler rotating 46 IPs (10,000+ requests an hour combined) slipped past IP rate limiting and was moved to a Managed Challenge at the edge; one channel lookup made D1 scan about 925 million rows a day across 3,500 streams until an index fix cut it to a few rows; and a signing key was re-imported on every request until he cached it in instance memory.
- His self-audit prompt (translated) asks an AI to check, read-only, how many billable calls each heartbeat/poll/retry/rate-limit triggers and whether rejected requests still consume resources, full-table scans and N+1 queries, uncached repeated initialisation, growth under IP-rotating crawlers or long-idle tabs, and whether there are per-product alerts and circuit breakers (accounting Durable Objects, D1 and Workers separately), then estimate risk at 24 hours idle and 10x abnormal traffic.
- Cloudflare's Durable Objects pricing page (read 2026-11-13) lists 1 million requests a month included on Workers Paid, then $0.15 per million, with HTTP requests, RPC sessions, WebSocket messages and alarm invocations all counted as requests.
Original sources
Published
Original post
Read on 𝕏Frank Zeng (@frankzeng2020) says an AI-written anti-abuse module pushed Durable Objects to 1.19 million requests against the 1 million included each month, costing him an extra $0.15; a budget alert email caught it, and the audit also found a D1 query path scanning 925 million rows a day and a signing key re-imported on every request. He shares a read-only self-audit prompt.
Frank Zeng🇨🇳🇨🇦
@frankzeng2020 · Original 𝕏 post
为了防爬虫写了段防滥用代码,结果防滥用代码先把 Cloudflare 额度干超了😂 幸好配了告警邮件。让 Claude Fable 5.2排查了一圈: Durable Objects 跑了 119 万次(月套餐 100 万),多付了 0.15 刀。 钱不多,但扒开一看全是深坑。 【1. 心跳把 DO 活活打崩】 播放页每 30 秒心跳 + 在线统计,居然要调 5 次 DO;连被拒绝的请求,都得先过一次 DO 做拦截检查。 一个页面挂着,单月耗掉 43 万次。只要 3 个人常开页面,整月额度直接归零。 👉 解法: 心跳移出 DO,边缘缓存拒绝结果,合并配额检查,加上降级熔断。 【2. 顺手揪出的三个雷区】 ① 低频爬虫穿透 IP 限流: 46 个 IP 轮换,合起来每小时 1 万+ 请求。已在边缘针对特征加上 Managed Challenge。 ② D1 一天狂扫 9.25 亿行: 查单个频道底层扫描 3500 条流,调整索引命中后改成按频道只扫几行。 ③ CPU 重复劳动: 签名密钥每次请求都重新导入,改成实例级内存缓存复用。 本来还想删 Worker 省钱,查完发现 8 个都有用,真正要命的是调用链设计。 修复已上线,等跑满 24 小时看降幅。 附上让 AI 自查项目的 Prompt,需要的自取: “请检查当前项目是否存在‘功能正常,但云服务用量被悄悄放大’的问题: 1. 心跳/轮询/重试/限流,一次操作触发多少次计费调用?被拒请求是否仍在消耗资源? 2. 数据库是否为返回少量数据而全表扫描(排查索引与 N+1)? 3. 是否存在未缓存的重复初始化、密钥导入或计算? 4. 遇到爬虫轮换 IP、长时间挂机时,用量如何增长? 5. 是否有分项告警与降级熔断?(Cloudflare 请隔离核算 DO、D1、Workers) 定位到代码,按挂机 24h 与 10 倍异常推算用量风险。只读审计,不改配置。”
@frankzeng2020 posts a shorter account of the same incident: 1.19 million calls against a 1 million monthly allowance after a budget alert email, five billable calls per 30-second heartbeat, 925 million D1 rows scanned a day for one channel and a signing key recomputed on every request.
Read on 𝕏Frank Zeng🇨🇳🇨🇦
@frankzeng2020 · Original 𝕏 post
防爬虫代码立大功: 成功把我们自己的云额度给干爆了😂 让 AI 写的防滥用模块,上线运转一切正常。 直到今天收到告警邮件,进去一查: 单月免费额度 100 万次,它一口气刷了 119 万次。 赶紧让Claude Fable 5.2 排查一下,原因让人哭笑不得: 只要用户开着网页,每 30 秒发一次心跳,底下就会触发 5 次计费调用;连被拦截下来的垃圾流量,也要走一遍计费逻辑。 只要有 3 个人常开标签页,免费额度当场蒸发。 更绝的是顺藤摸瓜揪出来的其他问题: • 查一个频道,底层的数据库一天扫了 9.25 亿行 • 签名密钥每次请求都重新算一遍,CPU 白白空转 AI 写业务逻辑是神,但对“按量付费”的感知几乎为零。 如果你的产品也部署在 Serverless / 云端上,建议去翻翻后台用量。 很多时候不是业务火了,纯粹是在给云厂商打黑工。
@frankzeng2020 replies with the full self-audit prompt for finding usage that is quietly amplified while features work normally.
Read on 𝕏Frank Zeng🇨🇳🇨🇦
@frankzeng2020 · Original 𝕏 post
附上让 AI 自查项目的 Prompt,需要的自取: “请检查当前项目是否存在‘功能正常,但云服务用量被悄悄放大’的问题: 1. 心跳/轮询/重试/限流,一次操作触发多少次计费调用?被拒请求是否仍在消耗资源? 2. 数据库是否为返回少量数据而全表扫描(排查索引与 N+1)? 3. 是否存在未缓存的重复初始化、密钥导入或计算? 4. 遇到爬虫轮换 IP、长时间挂机时,用量如何增长? 5. 是否有分项告警与降级熔断?(Cloudflare 请隔离核算 DO、D1、Workers) 定位到代码,按挂机 24h 与 10 倍异常推算用量风险。只读审计,不改配置。”
More to read
Michael Liyang: record every AI call in D1 and downgrade before the budget runs out
@Michael_liyang argues that on a free tier the danger is not one expensive call but not knowing which call is expensive: write each call's usage to D1 by user and model, have a daily Cron check budgets and downgrade first, and look at which user is burning quota rather than only the total.
opsfork: a MeloTTS retry loop produced a $391.50 Workers AI charge; a waiver was requested.
Cloudflare Community user opsfork (newsfork.com) asks for a full waiver of a $391.50 Workers AI charge for the billing period October 21 – November 20, 2026. The author says normal Workers AI spend is about $1–2 per day, but an unexpected incident involving the @cf/myshell-ai/melotts model sharply increased billable usage, mainly on November 18–19. According to the author, MeloTTS was scheduled for deprecation on November 20, 2026, yet repeated model failures began around November 17, before that date; those failures triggered a queue retry mechanism, and a defect in the author’s retry implementation amplified the failures, producing about 3.3 million queued messages. The author says almost all affected inference requests were failed or redundant retries of the same few video rendering jobs and produced no usable output. The author acknowledges responsibility for the retry defect, says the loop has been stopped, and lists safeguards already added, including retry limits, exponential backoff, a circuit breaker, and removal of MeloTTS. Requested resolution includes investigating the pre-deprecation failures, excluding the abnormal usage, waiving the amount attributable to the incident or issuing an equivalent one-time account credit, and a revised invoice; the author is willing to pay legitimate normal-usage charges. A formal billing adjustment request was submitted as Billing Support Case #02445560. Community MVP sjr replied that the author needs to work through the billing ticket and that the Community cannot help with billing issues. There is no Cloudflare staff reply on the public thread.
Cloudflare Billing Helper: a browser extension that shows free-allowance progress on the billing page
Meathill (@meathill1) built a Chrome extension that adds a panel to Cloudflare’s Billable Usage page: remaining free allowance for each billing line, projected exhaustion dates, estimated cost for the period, and a breakdown by Worker, KV namespace, D1 database, R2 bucket and Durable Object.