Skip to content

fix(telemetry-server): stop logging cancelled stats requests as errors - #4091

Merged
vavallee merged 2 commits into
mainfrom
fix/telemetry-stats-cancel-log
Nov 20, 2026
Merged

vavallee merged 2 commits into
mainfrom
fix/telemetry-stats-cancel-log

Conversation

@vavallee

@vavallee vavallee commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closing the getbindery.dev/stats tab before the dashboard queries finish made handleStatsPage log stats page error=context canceled at ERROR and write a 500 to a client that was already gone. /api/stats wrote the same 500 and logged nothing at all.

Both handlers now check statsClientGone: context.Canceled, context.DeadlineExceeded, or a done request context (the SQLite driver does not always wrap the context error). That case logs at Debug and returns without writing. Every other error logs at ERROR and returns 500, and /api/stats now logs it too.

No issue number; this came out of a pass over the telemetry server. Telemetry server changes have gone into the release notes before (#4021, #3844), so there is a fragment: changelog.d/telemetry-stats-cancel-log.md.

How it was verified

New stats_cancel_test.go, run against both handlers with a small writeSpy writer (the httptest recorder reports 200 for a handler that wrote nothing, so it cannot tell the two apart) and slog captured at Debug:

  • TestStatsHandlers_ClientGoneIsNotAnError: a cancelled context and a past deadline. Nothing written, no ERROR line, one DEBUG line.
  • TestStatsHandlers_DBErrorStillLogsError: closed DB on a live request. 500 with the internal error body, ERROR logged.

Fail before (source reverted, tests kept):

--- FAIL: TestStatsHandlers_ClientGoneIsNotAnError/canceled_/stats
    handler wrote status 500 with 15 body bytes, want nothing written
--- FAIL: TestStatsHandlers_ClientGoneIsNotAnError/canceled_/api/stats
    handler wrote status 500 with 15 body bytes, want nothing written
--- FAIL: .../deadline_exceeded_/stats and .../deadline_exceeded_/api/stats (same)
--- FAIL: TestStatsHandlers_DBErrorStillLogsError//api/stats   (no ERROR log)

All pass with the change. go test ./cmd/telemetry-server/... green, golangci-lint run ./cmd/telemetry-server/... 0 issues.

Checklist

  • Signed-off-by matches the author
  • Changelog fragment added
  • Tests added
  • No new dependency

Merging to main deploys: ping-server.yml pushes ghcr.io/vavallee/bindery-ping:sha-<commit>, and the infra repo's bump workflow (every 30 minutes) opens and auto merges a PR moving the pinned sha once that build is green.

🤖 Generated with Claude Code

When a visitor closes /stats, or an /api/stats request hits its deadline,
computeStats fails with the request context's error. Both handlers logged
that at ERROR (or, for /api/stats, not at all) and wrote a 500 to a client
that had already gone.

Treat context.Canceled, context.DeadlineExceeded, or a done request context
as "client gone": log at Debug and return without writing. Any other error
still logs at ERROR and returns 500, and /api/stats now logs it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vavallee
vavallee merged commit 2572494 into main Nov 20, 2026
44 checks passed
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