OG passthrough: benign fetch failures logged as ERROR on heavy/non-HTML resources, and client disconnects abort backend downloads mid-flight
Describe the bug
With openGraph.enabled: true in full-proxy mode (Anubis → Gitea/Forgejo backend), every challenge page render triggers an OG fetch of the requested URL. On heavy or non-HTML resources, the fetch fails and is logged at ERROR level from RenderIndex (lib/http.go), even though the failure is benign: the challenge page renders fine with ogTags = nil.
Observed over 12 h on a busy instance (~40 errors, all on git-heavy URLs — no normal HTML page ever fails):
| err | count | cause |
|---|---|---|
http get failed: Get ...: context canceled |
~20 | client disconnected while Anubis was fetching (crawler received the challenge page and walked away) |
http get failed: Get ...: context deadline exceeded (Client.Timeout ...) |
~10 | backend needed >5 s (git archive generation) — httpTimeout is hardcoded at 5 s (internal/ogtags/ogtags.go, /*todo: make this configurable?*/) |
content too large: exceeded 8388608 bytes |
5 | .bundle archives / huge compare pages > 8 MiB (hardcoded maxContentLength) |
failed to parse HTML: context deadline exceeded |
4 | same as timeout during body read |
missing Content-Type header |
1 | .diff response without Content-Type (cf. #253) |
Two side effects worth noting:
- Client-disconnect cancellation uses
r.Context()(RenderIndex→GetOGTags(r.Context(), ...)): when the visitor aborts, the in-flight fetch to the backend is cancelled mid-download. The backend (Forgejorepo.Download) then logs500 Internal Server Errorfor every cancelled archive generation — ~14/day, induced solely by OG fetches. - Failure outcomes are mostly not cached (only
net.Error.Timeout()gets an empty-cache entry forttl/2) —context canceled, oversized content and missing Content-Type re-trigger a fetch (and an ERROR) for every new visitor to the same URL. Related: #1643.
No functional impact: challenge pages render, real OG tags are still served and cached for normal HTML pages. It is log noise + avoidable backend load only.
Steps to reproduce
- Enable
openGraph: {enabled: true, ttl: 24h}in front of a git forge - Let crawlers with browser UAs hit
/archive/*.bundleand large/compareURLs - Observe ERROR lines in the Anubis logs and 500s in the backend access log
Expected behavior
Expected fetch failures (client gone, oversized body, non-HTML, timeout) should not be reported at ERROR level — DEBUG/WARN would be appropriate, since SLOG_LEVEL has no level above ERROR and operators cannot filter them out without dropping the whole message from their log pipeline.
Suggested improvements (any subset would help)
- Log benign OG fetch failures (
context canceled,content too large, unsupported/missing Content-Type) at DEBUG or WARN instead of ERROR - Fetch with a context detached from the visitor's request (keeping a detached 5 s timeout) so client disconnects don't cancel backend downloads mid-flight (avoids the induced backend 500s)
- Cache empty results for oversized/non-HTML/missing-Content-Type outcomes the same way timeouts already do (complements #1643)
- Make
httpTimeoutconfigurable (the TODO already inogtags.go:20)
Workaround
openGraph.override avoids all fetches but serves static values instead of the real ones — not desirable when genuine link previews are wanted.
Additional context
Anubis v1.27.0, full-proxy mode. Related: #1775 (same log line, different root cause — malformed URL in subrequest mode), #1643, #435.
Source: TecharoHQ/anubis