Skip to content

fix: fall back to stale user cache instead of erroring when sync fails - #71

Merged
jay739 merged 1 commit into
mainfrom
fix/usercache-fallback-to-stale-data-on-sync-failure
Jul 16, 2026
Merged

jay739 merged 1 commit into
mainfrom
fix/usercache-fallback-to-stale-data-on-sync-failure

Conversation

@jay739

@jay739 jay739 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

Found live tonight while trying to get a user list to send maintenance/downtime emails with Jellyfin down: GetUsers/SearchUsers returned a plain 500 "Couldn't get users" instead of the last successfully-cached list.

MaybeSync's own doc comment already states the intended design: "expecting you to use the old cache data" on a failed sync. That's honored correctly for a background sync (the common case), but GetUserDTOs discarded c.Ref on any MaybeSync error, including the blocking-sync case (Jellyfin unreachable long enough that WaitForSyncTimeout elapses too) — directly contradicting the cache's own stated purpose.

Change

GetUserDTOs now falls back to c.Ref when it has data and the sync failed, logging the failure instead of hiding it (via app.err.Printf), instead of returning nil, err unconditionally.

Limitation (documented, not fixed here)

This doesn't help retroactively for tonight's specific incident — the omnifin container was recreated several times while Jellyfin was already down, so the in-memory cache was empty (never populated), not stale. For tonight's actual mailing list, the persisted EmailAddress records were recovered directly from the on-disk badger DB (app.storage.GetEmails(), independent of UserCache) via a one-off read-only tool against a copy of the DB file — that data survives container restarts since it's real persistent storage, not an in-memory cache. This fix protects against the next time Jellyfin goes down after omnifin's been running long enough to populate the cache first.

Test plan

  • Simulate a sync failure with a populated cache (e.g. stop Jellyfin after omnifin has been up and synced at least once) — confirm GetUsers/SearchUsers return the stale list instead of a 500
  • Confirm normal operation (Jellyfin up) is unaffected
  • CI build/test passes

Found live 2026-07-16: with Jellyfin down, GetUsers/SearchUsers (the
admin panel's user list, needed to pick recipients for a maintenance
announcement) returned a plain 500 "Couldn't get users" instead of the
last successfully-cached list.

MaybeSync's own doc comment already states the intended behavior for a
failed sync: "expecting you to use the old cache data." That's true for
a background sync (the common case, WaitForSyncTimeout not yet
elapsed), but GetUserDTOs discarded c.Ref on ANY MaybeSync error,
including the blocking-sync case (Jellyfin unreachable long enough that
WaitForSyncTimeout elapses too) -- exactly contradicting the cache's
own stated purpose.

Falls back to c.Ref when it has data, logging the sync failure instead
of hiding it. Doesn't help retroactively (this session's cache was
empty going into tonight's incident, since the container had been
restarted several times while Jellyfin was already down), but fixes
the gap for any future outage where the cache had a chance to populate
first.
@jay739
jay739 merged commit 1793113 into main Jul 16, 2026
7 checks passed
@jay739
jay739 deleted the fix/usercache-fallback-to-stale-data-on-sync-failure branch July 16, 2026 12:49
jay739 added a commit that referenced this pull request Jul 16, 2026
Found live 2026-07-16, the second time in one night: the admin panel's
Users tab is completely unusable during a Jellyfin outage, even after
fixing the underlying panics/500s (#62-#71) -- GetUsers/SearchUsers
fundamentally need a live Jellyfin connection to list users, since
Jellyfin IS the user database. There's no way to make that endpoint
work without Jellyfin reachable.

What CAN work: app.storage's own persistent badger DB already stores
an EmailAddress record (Jellyfin ID, email, label, contact/admin
flags) per user, independent of Jellyfin's own availability. This was
previously only accessible via internal code paths (housekeeping
cleanup, migrations) with no API route exposing it -- recovering it
during tonight's incident required a one-off standalone Go program
reading the badger DB file directly.

Adds GET /users/persisted, returning every stored EmailAddress record.
Trades completeness (no online status, no Jellyfin username, no
last-active -- just enough to know who to email) for actually working
when Jellyfin is down. Same auth group (webAuth) as every other /users
route.
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

⌂ 换网址