DEV Community

Cover image for Silent Failure #25: The 30-Second Timeout That Filed Five Bug Reports
Renhua Wei
Renhua Wei

Posted on

Silent Failure #25: The 30-Second Timeout That Filed Five Bug Reports

At 01:04 on a Sunday, half asleep in front of a terminal, I watched this scroll past:

SCOPE: 141 article(s) = watch 138 + ledger-only 3 [5182479, 5182724, 5184648] | walked 4129 comment(s) | new 16
SCOPE FAILED: 5 article(s) not read [5025718, 5089063, 5096671, 5155594, 5177157] -- numbers above exclude them
Enter fullscreen mode Exit fullscreen mode

Five of my own posts, "not read". I typed a line about a flaky API into the shift report and went back to bed. That line took two more runs to disprove.

Eight hours later the next shift printed this:

SCOPE: 141 article(s) = watch 138 + ledger-only 3 | walked 4010 comment(s) | new 16
SCOPE FAILED: 3 article(s) not read [4943084, 4992435, 4996326]
Enter fullscreen mode Exit fullscreen mode

Three ids, and not one of them overlapped with the first five. If those posts were actually broken — deleted, made private, moved — the set would be stable. A set that rotates says the variable is the run, not the content. I almost wrote "flaky API" a second time, which is how a monitoring tool ends up reporting its own mood.

Then I wanted to blame position in the request order, since 141 articles go out one after another from the same process. I pulled the ids and checked where they sit in the watch list: 115, 116, 114, 133, 134 out of 138 — two contiguous blocks at the tail. The next run's three sat at 16, 17 and 18 — one contiguous block of three. Failures arriving as consecutive ids is the shape of a slow window, not the shape of five broken posts. That theory was wrong too, but wrong in a useful direction: it told me the unit here is seconds, not articles.

The test that settled it is boring. Pull the same five ids again with the timeout raised:

python3 - <<'EOF'
import json, urllib.request, time
for a in (5025718, 5089063, 5096671, 5155594, 5177157):
    t = time.time()
    r = urllib.request.urlopen("https://dev.to/api/comments?a_id=%d" % a, timeout=120)
    n = len(json.loads(r.read()))
    print(a, "roots=%d" % n, "%.2fs" % (time.time() - t))
EOF
Enter fullscreen mode Exit fullscreen mode

28, 17, 32, 29 and 2 root comments. Zero new ones, which is the real point: they had been readable the whole time. Later in the morning the three-id set came back 88, 52 and 0 roots, again with nothing fresh. Nine fetches, nine answers, zero posts broken.

I had a number for this the day before and threw it away. On 2026-12-05 one thread took 135 seconds on the first pull and 0.5 seconds on the retry, 3.5 hours apart, same URL, same params, same machine. 270x. I read the second number, wrote "transient, not an incident" in the log, and went on with the night. What I should have written is that the timeout is not a property of the article at all. It's a property of the minute.

My first attempt at a fix was to raise the timeout for everything to 120 seconds. I didn't ship it, and not because I'm disciplined: 141 articles times 120 seconds worst case is 47 minutes, and the next shift's cron slot is 30. The scan already makes 148 HTTP calls with 21 transport retries; retrying a 30-second timeout with a second 30-second timeout just spends your patience twice at the same price.

The part that should have scared me was the retry ledger. Every id that fails to read gets written into a small state file with an attempt counter, and once an id reaches three attempts the scanner exits 5 and calls itself blind:

SCOPE RETRY: 3 article(s) still unread from earlier runs (oldest 2026-12-06 01:04) | 4943084 x1, 4992435 x1, 4996326 x1
Enter fullscreen mode Exit fullscreen mode

An operator reading that concludes there's a monitoring outage. There was no outage. A slow API got promoted to a blind spot by a counter that never asked how long anything took. I wiped that file by hand twice in one night, 01:14 and 09:18, and a state file I have to clear by hand is not a chore, it's a design smell.

So the rule I'm writing into the scanner this week has three parts. Every fetch records elapsed milliseconds next to its result, because "timeout" without "after 30.01s" is a verdict with the evidence deleted. A timed-out id is retried once, immediately, with a longer ceiling — and only that id, not the other 140. And the retry ledger only escalates to blind after the same id fails on two different runs, since one run failing is a measurement of the minute.

None of that is clever. The clever thing I did was trust a bare word, and that was my mistake — a dumb one, since the word carried no number.

What I'd test first

Three curls, one minute apart, same id:

for i in 1 2 3; do curl -s -o /dev/null -w '%{time_total}\n' \
  "https://dev.to/api/comments?a_id=5032798"; sleep 60; done
Enter fullscreen mode Exit fullscreen mode

If those three numbers differ by more than 10x, the endpoint is the variable and your "unreadable" list is a latency sample wearing a status code. On the day I ran this by hand the spread was 0.5s to 135s on the same box.

Then check whether your own failure record can tell slow from dead:

grep -c 'elapsed' scanner.state
Enter fullscreen mode Exit fullscreen mode

If that returns 0, your incident report can't answer the only question that matters at 1am. It says the thing failed, not how long it sat there before someone gave up.

My take: a fixed per-request timeout on a 141-endpoint sweep measures the scanner's patience, not the endpoints' health, and the exit code it produces should say so. What's the p99 of the same API call from the machine that runs your health check — and does the alert you get at 3am contain that number, or just the word "failed"?

Top comments (1)

Collapse
 
member_7c8c7e8d profile image
Max K. •

That diagnosis is painfully relatable. Logging a bare timeout without elapsed_ms turns a temporary latency spike into a false outage report, and wiping a stuck retry ledger by hand is always a sign the state machine is missing a dimension. In our Python health checks we started emitting both status_class (timeout vs 5xx vs 4xx) and elapsed_ms right in the alert line, plus requiring failures across two separate windows before paging. When you retry a single timed-out ID immediately with a longer ceiling, do you cap total sweep duration so one slow tail does not push the next scheduled run off cadence?