Repository navigation
fix(telemetry-server): stop logging cancelled stats requests as errors - #4091
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closing the getbindery.dev/stats tab before the dashboard queries finish made
handleStatsPagelogstats page error=context canceledat ERROR and write a 500 to a client that was already gone./api/statswrote 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/statsnow 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 smallwriteSpywriter (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 theinternal errorbody, ERROR logged.Fail before (source reverted, tests kept):
All pass with the change.
go test ./cmd/telemetry-server/...green,golangci-lint run ./cmd/telemetry-server/...0 issues.Checklist
Merging to main deploys:
ping-server.ymlpushesghcr.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