Bug: Negative cache is never checked - checkNegativeCache is dead code #3

Zamknięty
otworzone 2026-02-09 00:56:07 +01:00 przez clawbot · 0 komentarzy
Collaborator

Bug

The Cache.checkNegativeCache() method in internal/imgcache/cache.go is implemented but never called anywhere in the codebase. The Service.Get() method goes straight to Lookup() for variant cache, then to processFromSourceOrFetch(), without ever consulting the negative cache.

Meanwhile, StoreNegative() IS called from fetchAndProcess() when an upstream error occurs, so negative entries accumulate in the database but are never read.

Impact

Failed upstream fetches are re-attempted on every request instead of being short-circuited by the negative cache. This means:

  • Repeated requests for broken/404 images hammer the upstream server
  • The NegativeTTL configuration has no effect
  • Increased latency for known-bad URLs
  • The negative_cache table grows unbounded (only cleaned by CleanExpired which also isn't called regularly)

Fix

Add a negative cache check at the beginning of Service.Get(), before attempting to fetch from upstream. If the URL is in the negative cache, return an appropriate error immediately.

## Bug The `Cache.checkNegativeCache()` method in `internal/imgcache/cache.go` is implemented but never called anywhere in the codebase. The `Service.Get()` method goes straight to `Lookup()` for variant cache, then to `processFromSourceOrFetch()`, without ever consulting the negative cache. Meanwhile, `StoreNegative()` IS called from `fetchAndProcess()` when an upstream error occurs, so negative entries accumulate in the database but are never read. ## Impact Failed upstream fetches are re-attempted on every request instead of being short-circuited by the negative cache. This means: - Repeated requests for broken/404 images hammer the upstream server - The `NegativeTTL` configuration has no effect - Increased latency for known-bad URLs - The negative_cache table grows unbounded (only cleaned by `CleanExpired` which also isn't called regularly) ## Fix Add a negative cache check at the beginning of `Service.Get()`, before attempting to fetch from upstream. If the URL is in the negative cache, return an appropriate error immediately.
clawbot przypisuje to na siebie 2026-02-09 00:56:07 +01:00
sneak zamknął(-ęła) to zgłoszenie 2026-02-09 01:32:27 +01:00
Zaloguj się, aby dołączyć do tej rozmowy.
Uczestnicy 1
Powiadomienia
Termin realizacji
Brak ustawionego terminu realizacji.
Zależności

No dependencies set.

Reference: sneak/pixa#3